MVC4剑道项目Ajax.BeginForm UpdateTargetId问题 [英] MVC4 Kendo Project Ajax.BeginForm UpdateTargetId Issue

查看:189
本文介绍了MVC4剑道项目Ajax.BeginForm UpdateTargetId问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用一些code从现有的MVC3项目MVC4一个新项目。我可以强迫我的形式阿贾克斯重新加载特定的DIV,而不是使用常规的方法提出,只有在测试doSomthing()JavaScript函数。我缺少什么?

I have just started a new project in MVC4 using some code from an existing MVC3 project. I can force my form to ajax reload the specific DIV, but not using the normal submit method, only with the test doSomthing() javascript function. What am I missing?

要澄清:第一个按钮不工作的权利,第二个呢 - 但我不想这样做的。

To clarify: The first button does not work right, the second one does - but I don't want to do it that way.

查看

@using (Ajax.BeginForm("Method1", null,
new AjaxOptions { HttpMethod = "post", UpdateTargetId = "divPartial1" },
new { id = "form1" }))
{
    <div class="data">
        @Html.LabelFor(x => x.TotalSubmitted, new { @class = "total" })<div class="number total">@Html.FormatValue(Model.TotalSubmitted, "{0:n0}")</div>
        ...
    </div>
    <div class="details">
        <div id="divPartial1">
            @Html.Partial("ReportDashboardAppPartial")
        </div>
    </div>
    <div style="text-align: center;">
        <button type="submit" class="k-button"><span class="k-icon k-i-search" /></button>
        <button type="button" name="Save" value="Save" onclick="doSomething(); return false;"><span class="k-icon k-i-search" /></button>
    </div>
}
<script type="text/javascript">
    function doSomething() {
        $.ajax({
            url: '@Url.Action("Method1", "Controller")',
        type: 'post',
        data: $('form#form1').serialize(),
        success: function (result) {
            $('#divPartial1').html(result);
        }
    });
}
</script>

_layout

_Layout

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

我知道这应该工作。

I know this should work.

推荐答案

我有同样的问题。解决的办法是在_Layout.cshtml页面中添加的声明。

I had the same problem. The solution is to add a statement in _Layout.cshtml page.

@ Scripts.Render(〜/包/ jqueryval)

@Scripts.Render("~/bundles/jqueryval")

ScriptBundle(〜/包/ jqueryval),如下

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

这篇关于MVC4剑道项目Ajax.BeginForm UpdateTargetId问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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