gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:59:37 24 4
gpt4 key购买 nike

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

澄清一下:第一个按钮不能正常工作,第二个可以 - 但我不想那样做。

看法

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

_布局
@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>

我知道这应该有效。

最佳答案

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

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

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

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

关于asp.net-mvc-4 - MVC4 剑道项目 Ajax.BeginForm UpdateTargetId 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14712972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com