Ajax.BeginForm 让我抓狂
ASP.NET MVC3
我有一个最初在 div 内呈现的部分视图。以下是部分代码:
@model Venue.Models.Validation.CustomerRequestModel
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="/Scripts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/Scripts/MicrosoftMvcAjax.js"></script>
<script type="text/javascript" src="/Scripts/MicrosoftMvcValidation.js"></script>
@{ Html.RenderPartial("Message"); }
@Html.ValidationSummary()
@using (Ajax.BeginForm(
"Customer",
"Service",
null,
new AjaxOptions()
{
HttpMethod = "post",
InsertionMode = InsertionMode.Replace,
LoadingElementDuration = 100,
LoadingElementId = "loading-customer",
OnBegin = "hideSubmitButton",
OnSuccess = "hideForm",
OnComplete = "showSubmitButton",
OnFailure = "showErrorMessage",
UpdateTargetId = "formclientes",
},
new
{
id = "customer-form"
}))
{
// Fields are all type="text" although some are numbers.
<input type="text" name="Address" class="clientes_form" />
}
操作:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Customer(CustomerRequestModel customer)
{
// ...
}
在立即窗口中,这就是我得到的:
this.Request.IsAjaxRequest()
false
为什么?!
ASP.NET MVC3
I have a partial view that is initially rendered inside a div. The following is the partial code:
@model Venue.Models.Validation.CustomerRequestModel
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="/Scripts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/Scripts/MicrosoftMvcAjax.js"></script>
<script type="text/javascript" src="/Scripts/MicrosoftMvcValidation.js"></script>
@{ Html.RenderPartial("Message"); }
@Html.ValidationSummary()
@using (Ajax.BeginForm(
"Customer",
"Service",
null,
new AjaxOptions()
{
HttpMethod = "post",
InsertionMode = InsertionMode.Replace,
LoadingElementDuration = 100,
LoadingElementId = "loading-customer",
OnBegin = "hideSubmitButton",
OnSuccess = "hideForm",
OnComplete = "showSubmitButton",
OnFailure = "showErrorMessage",
UpdateTargetId = "formclientes",
},
new
{
id = "customer-form"
}))
{
// Fields are all type="text" although some are numbers.
<input type="text" name="Address" class="clientes_form" />
}
The action:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Customer(CustomerRequestModel customer)
{
// ...
}
In the immediate window, this is what I get:
this.Request.IsAjaxRequest()
false
Why?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 web.config 文件中有 jquery.unobtrusive-ajax.js,则应包含 jquery.unobtrusive-ajax.js
,该文件由 MVC3 RC2 默认启用。
并且还要删除最后 3 个(MicrosoftAjax、MicrosoftMvcAjax 和 MicrosoftMvcValidation)脚本引用,因为在使用非侵入式版本时不需要它们。
有关不显眼 Ajax 的更多信息,作者: Brad Wilson
You should include jquery.unobtrusive-ajax.js if you have
in your web.config file, which is default enabled by MVC3 RC2.
And also delete the last 3 (MicrosoftAjax, MicrosoftMvcAjax and MicrosoftMvcValidation)script references, because you don't need them when using unobtrusive version.
More info about unobtrusive Ajax by Brad Wilson