Asp.net mvc 4 MVC4剑道项目Ajax.BeginForm UpdateTargetId问题

Asp.net mvc 4 MVC4剑道项目Ajax.BeginForm UpdateTargetId问题,asp.net-mvc-4,kendo-ui,Asp.net Mvc 4,Kendo Ui,我刚刚在MVC4中启动了一个新项目,使用了现有MVC3项目中的一些代码。我可以强制我的表单用ajax重新加载特定的DIV,但不使用普通的submit方法,只使用test doSomthing()javascript函数。我错过了什么 澄清一下:第一个按钮不正常,第二个按钮正常,但我不想这样做 看法 @使用(Ajax.BeginForm(“Method1”),null, 新的AjaxOptions{HttpMethod=“post”,UpdateTargetId=“divPartial1”}, 新

我刚刚在MVC4中启动了一个新项目,使用了现有MVC3项目中的一些代码。我可以强制我的表单用ajax重新加载特定的DIV,但不使用普通的submit方法,只使用test doSomthing()javascript函数。我错过了什么

澄清一下:第一个按钮不正常,第二个按钮正常,但我不想这样做

看法

@使用(Ajax.BeginForm(“Method1”),null,
新的AjaxOptions{HttpMethod=“post”,UpdateTargetId=“divPartial1”},
新的{id=“form1”})
{
@LabelFor(x=>x.TotalSubmitted,new{@class=“total”})@Html.FormatValue(Model.TotalSubmitted,“{0:n0}”)
...
@Html.Partial(“ReportDashboardAppPartial”)
}
函数doSomething(){
$.ajax({
url:'@url.Action(“Method1”,“Controller”)',
键入:“post”,
数据:$('form#form1')。序列化(),
成功:功能(结果){
$('#divPartial1').html(结果);
}
});
}
_布局

@model BaseViewModel
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    <link href="@Url.Content("~/Content/kendo.compatibility.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2012.3.1114/kendo.common.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2012.3.1114/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/kendo/2012.3.1114/kendo.default.min.css")" rel="stylesheet" type="text/css" />
    @RenderSection("styles", false)
    <script src="@Url.Content("~/Scripts/kendo/2012.3.1114/jquery.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo/2012.3.1114/kendo.all.min.js")"></script>
    <script src="@Url.Content("~/Scripts/kendo/2012.3.1114/kendo.aspnetmvc.min.js")"></script>
    @RenderSection("scripts", false)
</head>
<body>
    @Html.Partial("_AlertWindow")
    <div id="wrapper">
        <header>
            <div id="logindisplay">
                @Html.Partial("_LoginPartial")
            </div>
            <a href="@Url.Action("Index", "Home")">
                <div id="logo"></div>
            </a>
            <div id="title">
                <h1>Ha!</h1>
            </div>
            @(Html.Kendo().Menu().Name("Menu").BindTo("Main").SecurityTrimming(true))
        </header>
        <div id="main">
            @RenderBody()
        </div>
        <footer>
            <div id="version">@Html.ActionLink("Version " + @Model.CurrentVersion, "About", "Home")</div>
        </footer>
    </div>
    @RenderSection("end_scripts", false)
</body>
</html>
@model BaseViewModel
@视图包。标题
@Scripts.Render(“~/bundles/modernizer”)
@Scripts.Render(“~/bundles/jquery”)
@渲染部分(“样式”,false)
@RenderSection(“脚本”,false)
@Html.Partial(“\u AlertWindow”)
@Html.Partial(“_LoginPartial”)
哈
@(Html.Kendo().Menu().Name(“Menu”).BindTo(“Main”).SecurityTrimming(true))
@RenderBody()
@ActionLink(“版本”+@Model.CurrentVersion,“关于”,“主页”)
@RenderSection(“结束脚本”,false)

我知道这应该行得通。

我也有同样的问题。解决方案是在_Layout.cshtml页面中添加一条语句

@Scripts.Render(“~/bundles/jqueryval”)

ScriptBundle(“~/bundles/jqueryval”)的定义如下

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
            "~/Scripts/jquery.unobtrusive*",
            "~/Scripts/jquery.validate*"));

注意:我必须在RenderBody()之后将此添加到_layout.cshtml的末尾。在我的头与代码碰撞太久后救了我。谢谢
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
            "~/Scripts/jquery.unobtrusive*",
            "~/Scripts/jquery.validate*"));