Request.IsAjaxRequest returning false on POST
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()
is returning true for the Edit method that accepts http GET, but false for Edit method accepting http POST.
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 })%>
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>
</h开发者_StackOverflow中文版4>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
Is this by design, am I doing something wrong, and how do I fix this?
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.
I am pretty surprised to hear that. You can install the Firebug addon for Firefox, and monitor network traffic from the NET tab. Only aSync requests will show up in the XHR sub-tab.
精彩评论