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

1
$('#frmHomeContact').on('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(){
            console.log('Successful submission.');
        }
    });
    return false; //submitting the form will no longer cause the browser to refresh.
});
于 2013-10-24T19:58:40.500 回答
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 回答