Ajax.BeginForm快把我逼疯了 [英] Ajax.BeginForm driving me crazy

查看:221
本文介绍了Ajax.BeginForm快把我逼疯了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个初步呈现一个div内的局部视图。以下是部分code:

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" />
}

动作:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Customer(CustomerRequestModel customer)
{
  // ...
}

在即时窗口,这是我得到:

In the immediate window, this is what I get:

this.Request.IsAjaxRequest()
false

为什么?!

推荐答案

您应该包括jquery.unobtrusive-ajax.js如果你有

You should include jquery.unobtrusive-ajax.js if you have

<add key="UnobtrusiveJavaScriptEnabled" value="true"/>

在你的web.config文件,这是违约MVC3 RC2启用。
并且还删除最后3(MicrosoftAjax,MicrosoftMvcAjax和MicrosoftMvcValidation)脚本引用,因为使用不显眼的版本,当你不需要他们。

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

这篇关于Ajax.BeginForm快把我逼疯了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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