MVC - 使用JQuery

时间:2017-01-31 05:46:31

标签: jquery ajax asp.net-mvc ajax.beginform

我在部分视图中使用Ajax.BeginForm来提交数据。

部分视图 - _getCategoryMaster.cs

<div>
    @using (Ajax.BeginForm("Submit", "CategoryMasterDataEntry", new AjaxOptions { OnSuccess = "OnDatatSuccess", OnFailure = "OnDataFailure", HttpMethod = "POST" }, new { enctype = "multipart/form-data" }))
    {
           <div style="float:left;width:100%;">
                <hr class="horizontal-line-bottom" />
                <div class="form-buttons tab-footer">
                    <button class="btn btn-md" type="submit" id="saveData" @if (TempData["DisplayAccess"].ToString() == "view") { <text> disabled </text>  }>SAVE</button>
                </div>
            </div>
     }
</div>

现在我试图从我的父视图调用此提交事件来自Jquery的链接的click事件

家长视图 -

<html>
<head>
<script type="text/javascript">
 $(document).on('click', '.getProducts', function (e) {
        alert("Start");

        $('form#ajaxForm').trigger('submit');

        alert("End");
</script>
</head>
<body>
 <a id="anchId" href="javascript:void(0);" class="getProducts">
 <img src="~/Images/bullets.png" class="bullet-image" /> 
  <span class="menu-text">LinkName</span> 
  </a>
</body>
</html>

但它没有触发提交局部视图的事件。我正在收到这些警报(开始和结束)。但它没有解雇提交事件。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:3)

您没有id="ajaxForm"的表单。使用new { enctype = "multipart/form-data" }

替换Ajax.BeginForm()(因为您无法使用new { id= "ajaxForm" }提交文件,这是毫无意义的)
@using (Ajax.BeginForm("Submit", "...", new AjaxOptions { ... }, new { id = "ajaxForm" }))

或仅使用$('form').trigger('submit');

相关问题