0

私は奇妙な問題に直面しています。私はcshtmlフォームを持っています:

  <label class="pre_req_questions_width">
                    @Html.RadioButton("radioGroup" + Model.ID, "1", (Model.ExpectedResponse == 1 ? true : false), new { id = "rbtnYes", style = "margin-top:0px; margin-right:10px;" })Yes</label>
                <label class="pre_req_questions_width">
                    @Html.RadioButton("radioGroup" + Model.ID, "2", !(Model.ExpectedResponse == 1 ? true : false), new { id = "rbtnNo", style = "margin-top:0px;margin-right:10px;" })No</label> 

フォームの送信時に、次のようなラジオ グループの値を取得しています。

int radioValue =  int.Parse(fc.GetValue(controlID).AttemptedValue);

から呼び出すと正常に動作します@Html.BeginForm()が、次のように ajax 経由でフォーム コレクションを送信しようとすると:

input = $(':input')

        $.ajax({
            type: "POST",
            url: '@Url.Action("SavePrerequisiteQuestion", "Dashboard", new { id = @Model.ID })',
            data: input,
            dataType: "html",
            success: function (msg) {
             alert("fine");
            }, error: function (req, status, error) {
                    // with error   
                    alert(error);
                }
        });

選択/送信された値を送信するのではなく、この「1,2」のように両方の値を送信します。

4

3 に答える 3

0

@Html.Beginform を元に戻し、jQuery でフォーム送信を乗っ取ることができます

$('#formID').on('submit', function(e){
    e.preventDefault();  // Just to stop the automatic Non Ajax submission of the form

    $.post($(this).attr('action'), $(this).serialize(), function (data) {
       //do stuff on success callback
       alert("fine");
    });
});

$(this).attr('action') を実行することにより、以下のパスで Html.BeginForm 自体からアクション パスを継承できます。 form 次に、 $(this).serialize() を使用して、上の人が提案したようにフォーム全体をシリアル化します

于 2013-05-24T14:41:48.650 に答える