MVC-使用JQuery触发主视图中部分视图的提交事件 [英] MVC - Trigger submit event of partial view in main view using JQuery

查看:93
本文介绍了MVC-使用JQuery触发主视图中部分视图的提交事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在局部视图中使用Ajax.BeginForm提交数据.

I am using Ajax.BeginForm in my partial view to submit the data.

部分视图-_getCategoryMaster.cs

Partial view - _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事件的父视图中调用此Submit事件

Now i'm trying to call this submit event from my parent view on the click event of the link from Jquery

父视图-

<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>

但是它不触发部分视图的提交事件.我收到那些警报(开始和结束).但是它没有触发提交事件.

But its not firing that submit event of the partial view. I am getting those alerts (start and End). But its not firing that submit event.

我在做什么错了?

推荐答案

您没有带有id="ajaxForm"的表单.用new { id= "ajaxForm" }

You do not have a form with id="ajaxForm". Replace new { enctype = "multipart/form-data" } (which is pointless since you cannot submit files using Ajax.BeginForm()) with new { id= "ajaxForm" }

@using (Ajax.BeginForm("Submit", "...", new AjaxOptions { ... }, new { id = "ajaxForm" }))

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

这篇关于MVC-使用JQuery触发主视图中部分视图的提交事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆