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?

2 Answers 2

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.

3
  • Good call. I had the "CloseDialog" in the (document).ready(function() { of the page.
    – oltman
    Nov 18, 2009 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, 2009 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, 2009 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.

5
  • As expected, the GET request shows up while the POST request does not. Any ideas why this may be?
    – oltman
    Nov 18, 2009 at 14:16
  • Can you post the contents of your form? Nov 18, 2009 at 14:51
  • Form contents posted. I don't seen anything in here that could be causing a problem, but I guess that's why I'm here in the first place :)
    – oltman
    Nov 18, 2009 at 15:06
  • No clue... I don't suppose the page is available on the WWW somewhere, is it? Nov 18, 2009 at 15:26
  • Nope. I think there may be an issue with OnComplete = "CloseDialog" that's causing it to fall back to a synchronous call.
    – oltman
    Nov 18, 2009 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.