2

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>
        </h4>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
<% } %>

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

Community
  • 1
  • 1
oltman
  • 1,772
  • 1
  • 14
  • 24

2 Answers2

2

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.

Nate
  • 1,669
  • 15
  • 22
  • Good call. I had the "CloseDialog" in the `(document).ready(function() {` of the page. – oltman Nov 18 '09 at 15:59
  • Any idea why it reverts to a regular postback instead of throwing some kind of exception or letting the developer know what's going on in some way? – oltman Nov 18 '09 at 16:00
  • It does throw an exception but its a js exception so, client-side. If you put a few breakpoints in the MvcAjax file, you'll see the exception thrown. Once the error occurs, the browser takes over and submits the form like any other form. – Nate Nov 18 '09 at 16:10
0

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.

Josh Pearce
  • 3,399
  • 1
  • 23
  • 24