Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX.BeginForm PostURL being corrupted

I'm experiencing a strange problem while trying to use the Ajax.BeginForm method of ASP.NET MVC3. The form renders properly on the page with the correct action attribute. However, when the form is submitted, the "OnFailure" event is returning a "Not Found" 404 error.

If I watch the request with fiddler, I see that the post URL is "/[Object NodeList]" which is obviously invalid.

My Razor code is as follows:

@using (Ajax.BeginForm("Save", "Items", new AjaxOptions { UpdateTargetId = "itemContainer", InsertionMode = InsertionMode.Replace, OnFailure = "onFailure"}))
{
    <div style="position:absolute; bottom:20px; left:200px;">
        <button type="submit" id="Save" name="action" value="Save">Save</button>
        <button type="submit" id="Cancel" name="action" value="Cancel">Cancel</button>
    </div>
}
like image 260
jbrunken Avatar asked Dec 07 '11 21:12

jbrunken


1 Answers

The problem was using "action" for the name attribute on the submit buttons. As soon as I changed the name attribute to a different value, everything started working perfectly.

I'm guessing that there is a jQuery selector in the unobtrusive ajax library that got confused.

like image 76
jbrunken Avatar answered Dec 07 '22 17:12

jbrunken