Request.IsAjaxRequest返回false在POST [英] Request.IsAjaxRequest returning false on POST

查看:206
本文介绍了Request.IsAjaxRequest返回false在POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是类似这个,我有一个类似的问题,而是一个最大的区别是,我使用了Ajax的helper方法( Ajax.ActionLink Ajax.BeginForm ),而不是处理AJAX的使用jQuery。

My question is similar to this one and I am having a similar issue, but a big difference is that I'm using the Ajax helper methods (Ajax.ActionLink and Ajax.BeginForm) instead of handling the AJAX with jQuery.

Request.IsAjaxRequest()将返回适用于接受HTTP GET的编辑方法,但假的编辑方法接受HTTP POST。

Request.IsAjaxRequest() is returning true for the Edit method that accepts http GET, but false for Edit method accepting http POST.

的GET请求是从生成的链接:

The GET request comes from a link generated by:

<%=Ajax.ActionLink(item.Name, "Edit", "Device",
     new { id = item.ID },
     new AjaxOptions { HttpMethod= "GET", UpdateTargetId = "ModalDialog" },
     new { name = item.Name })%>

POST请求来自该code生成的表格:

The POST request comes from a form generated by this code:

<% using (Ajax.BeginForm("Edit", "Device", new { id = Model.ID }, new AjaxOptions { OnComplete = "CloseDialog" }))
{ %>
    <fieldset>
         <h4>
            <label for="Name">Name</label>
        </h4>
        <%= Html.TextBox("Name", null, new { @class = "required" })%>

        <h4>
            <input type="checkbox" id="IsActive" name="IsActive" <% if (Model.IsActive)%> <%=Html.Encode("checked=''")%> />
            <label for="IsActive">Unit Is Active</label>
        </h4>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
<% } %>

这是由设计,我是不是做错了什么,以及如何解决这一问题?

Is this by design, am I doing something wrong, and how do I fix this?

推荐答案

一切有看起来不错。一个念头:在你的 AjaxOptions 您指定一个CloseDialog功能的onComplete 。有一个被创建,它是访问的形式?如果没有,MvcAjax脚本将抛出一个错误,并且形式将恢复为常规回发。

Everything there looks fine. One thought: in your AjaxOptions you specify a "CloseDialog" function for OnComplete. Has that been created and is it accessible to the form? If not, the MvcAjax script will throw an error and the form will revert to a regular postback.

这篇关于Request.IsAjaxRequest返回false在POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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