0

送信ボタンのある Html フォームがあり、フォーム内に個別に送信する必要がある複数のセクションがあります。Html はネストされたフォームをサポートしていないため、どうすればそれを実行できますか? また、提出前に各セクションを検証する必要があります。

<%  using (Html.BeginForm("actionName", "controllerName", FormMethod.Post))
        { %>
<form id="frmHomeContact" method="post"  >
                       -- a partial view is rendered here
                       <div class="grid-2-12">

                            <input style="width: 100%;" type="button" title="save" value="save" />
                        </div>
                      </form>

<%}%>

質問が明確でない場合はお知らせください。

4

2 に答える 2

0

HTML コードは次のようになります。

<%  using (Html.BeginForm("actionName", "controllerName", FormMethod.Post),new { id = "frmHomeContact" })
        { %>
<form  method="post"  >
                       -- a partial view is rendered here
                       <div class="grid-2-12">

                            <input style="width: 100%;" type="button" title="save" value="save" />
                        </div>
                      </form>
<%}%>
<script type="text/javascript">
    $("#frmHomeContact").submit(function() {
    var $this = $(this); // catch a reference to the form
        $.ajax({
            url: '/', //this should probably be the path to your controller
            type: 'POST',
            data: $this.serialize(), //name=George&msg=hello..etc <--note $this not $(this)
            success: function(){
                alert('Successful submission.');
            }
        });
        return false; //submitting the form will no longer cause the browser to refresh.
    });
</script>

を使用して個々のテキスト ボックスの値を取得しvar txtname= $('#txtid').val();、txt 名が空かどうかを確認できます。

于 2013-10-25T14:33:21.883 に答える