0

radiobuttonfor から取得した ID を MainPage コントローラーに渡す方法 - Edit1 actionresult in View. どんな助けでも大歓迎です!ありがとう!

// for ループで表示してコンテンツとラジオボタンを表示する

@foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.SurveyTitle)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.DateCreated)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.DateClosing)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.User)
                    </td>
                    <td>
                        @Html.RadioButtonFor(modelItem => item.SurveyId, new {id = item.SurveyId})
                    </td>
                </tr>
            }


          <button type="submit" class="btn btn-primary" id="edit">Edit</button>

// どのラジオボタン ID が選択されているかを検出して送信するためのボタンのスクリプト

<script>            
        $('#edit').click(function () {

            var id = $('input[type=radio]:checked').val();
            alert(id);


        });

         </script>

// ID を取得して SurveyID を取り出すコントローラー

[HttpPost]
             public ActionResult Edit1(int id=0)
            {
                survey survey = db.surveys.Single(s => s.SurveyId == id);
                if (survey == null)
                {
                    return HttpNotFound();
                }
                return View(survey);
            }
4

3 に答える 3

0

これを試して:

http://api.jquery.com/jQuery.post/

または、IDを非表示のテキストフィールドに配置し、送信ボタンのクリックをトリガーします(ページにWebフォームがある場合)

于 2012-10-26T13:39:49.997 に答える
0

ユーザーがラジオ ボタン リストによって設定された特定の ID に基づいて編集をクリックしたときに、ウィンドウの場所を変更しようとしているようです。

次のようなことができると思います。

$('#edit').click(function () {

    var id = $('input[type=radio]:checked').val();
    window.location.href='/MainPage/Edit1/'+id;
    //window.location.href='/MainPage/Edit1/?id='+id; //if {controller}/{action}/{id} isn't setup in the routing class.

});
于 2012-10-26T13:55:39.543 に答える
0

あなたが話しているこの送信ボタンはどこにありますか? ですか#edit?POSTアクションに到達したい場合は、フォームをPOSTさせる必要があります。int idまた、ラジオを次のように変更しない限り、アクションにバインドされません@Html.RadioButton("id", item.SurveyId)

于 2012-10-26T14:31:38.480 に答える