2

私は現在、このコードを持っています:

foreach (var item in Model.LstBagels)
            {

                    @Html.Hidden("txtId", item.BagelId)
                    <div id="bagel">                     
                        <div id="bagel-info">                  
                            <div id="bagel-image">
                                <img src="@Url.Content(String.Format("~/Resources/Images/{0}.jpg", item.Image))" alt="" />
                            </div> 

                            @if (@BestelBagels.Resources.Views.Index.IndexStrings.Name == "Name")
                            {
                                <h2>@Html.DisplayFor(m => item.Name)<br /></h2>
                            }
                            else
                            {
                                <h2>@Html.DisplayFor(m => item.NameFr)<br /></h2>
                            }

<input class="button widthorder" type="submit" name="BtnOrder" value="@BestelBagels.Resources.Views.Index.IndexStrings.Bestellen"/>
                        </div>   
                    </div>

そして、ボタンを押すと、常にすべてのアイテムから最初のID、またはすべてのアイテムのリストを受け取ります。しかし、提出したIDをどのように受け取ることができますか? 私のtxtIdは、常にアイテムソースの最初のIDです。

あいさつ

4

1 に答える 1

3

ボタンはどこですか?

Form HtmlHelpersを使用して、フォーム内のすべての div をワープしてみませんか?

この投稿を確認できます:

foreach (var item in Model.LstBagels)
            {
 @using (Html.BeginForm('ActionName', 'ContollerName', FormMethod.Post) {
                    @Html.Hidden("txtId", item.BagelId)
                    <div id="bagel">                     
                        <div id="bagel-info">                  
                            <div id="bagel-image">
                                <img src="@Url.Content(String.Format("~/Resources/Images/{0}.jpg", item.Image))" alt="" />
                            </div> 

                            @if (@BestelBagels.Resources.Views.Index.IndexStrings.Name == "Name")
                            {
                                <h2>@Html.DisplayFor(m => item.Name)<br /></h2>
                            }
                            else
                            {
                                <h2>@Html.DisplayFor(m => item.NameFr)<br /></h2>
                            }
<input class="button widthorder" type="submit" name="BtnOrder" value="@BestelBagels.Resources.Views.Index.IndexStrings.Bestellen"/>
                        </div> 

}

js 以外のブラウザーをあまり気にせず、アクションで GET を受け入れる場合は、フォームの使用をスキップして、アクション ボタンを作成するだけで済みます。

<input class="button widthorder" type="button" name="BtnOrder" onClick="window.location='@Url.Action("ActionName","ControllerName"   , new { txtId= item.BagelId })'" value="@BestelBagels.Resources.Views.Index.IndexStrings.Bestellen"/>
于 2013-11-04T11:17:31.107 に答える