Request.IsAjaxRequest返回false在POST

编程入门 行业动态 更新时间:2024-10-24 08:23:11
本文介绍了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

本文发布于:2023-10-29 07:58:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:IsAjaxRequest   Request   POST   false

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!