加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax.BeginForm()没有工作MVC – 未捕获的javascript错误 – 意

发布时间:2020-12-16 02:48:43 所属栏目:百科 来源:网络整理
导读:我想在MVC中做ajax表单这是我的步骤: 我创建了Model类MyModel: public class MyModel{ [Required] public string Name { get; set; } public int iexNum { get; set; } public InMyModel inMyModel { get; set; } public string selectedCombo { get; set;
我想在MVC中做ajax表单这是我的步骤:
我创建了Model类MyModel:

public class MyModel
{
    [Required]
    public string Name { get; set; }
    public int iexNum { get; set; }
    public InMyModel inMyModel { get; set; }
    public string selectedCombo { get; set; }
    public List<string> collection { get; set; }
}

public class InMyModel
{
    public string Name { get; set; }
    public int Num { get; set; }
}

我在我的布局中添加了这两个脚本:

<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

这是我的形式:

@{
    Html.EnableClientValidation();
}
@using (Ajax.BeginForm("MyFunction","Home",new AjaxOptions
    {
        HttpMethod = "POST",OnBegin = "function(){ loadingPanel.Show(); }",OnComplete = "function(){ loadingPanel.Hide(); }",UpdateTargetId = "mycontent",InsertionMode = InsertionMode.Replace
    },new
    {
        id = "validationForm",@class = "edit_form",style = "height: 200px; width: 600px;"
    }))
{

    <div id="mycontent">
        @Html.Partial("_ajaxForm",Model)
    </div>

}

当我运行应用程序并按下表单我得到javascript uncaught错误,如在此截图中:

正如您所看到的,jquery.unobstusive.ajax.min.js中存在未被捕获的错误
有人帮忙!?

解决方法

我发现问题这条线路不好!

OnBegin = "function(){ loadingPanel.Show(); }",

我改成了:

OnBegin = "onBegin",OnComplete = "onEnd",

并在我的javascript文件中实现这些功能,这是工作!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读