views:

51

answers:

2

I am trying to submit a delete link click via a http post to my asp.net mvc controller. While my code below works for chrome it does not work in IE8. Any pointer will be very useful.

Setup:- Browser: IE8 jQuery: 1.4.1 MVC: 2.0

The delete link is:-

<a title="Delete contact" href="/Contacts/Delete/<%= Model.Contact.Id %>" class="delete" rel="Are you sure you want to delete <%= Html.Encode(Model.Contact.Name) %>?">Delete</a>

and the jqeury handler for the click of delete is

$("a.delete").click(function() {
if (confirm($(this).attr("rel"))) {
    var form = "<form method='POST' action='" + $(this).attr("href") + '" style='display:none;'></form>";
        $(form).submit();
    }
    return false; });
+2  A: 

IE does not submit disabled elements in a form, so maybe it's the same with empty forms.

It's not exactly a solution, but I would do that without creating a form. You can just use $.ajax or $.post and build the required URL with Url.Action(...), then call document.reload().

Dario Solera
This is how I would do it. Easier to debug and manage with `$.post`
Alastair Pitts
*"IE does not submit disabled elements in a form..."* No browser submits disabled elements in a form -- at least, not if they want to follow the specification, which says not to: http://www.w3.org/TR/html5/forms.html#form-submission-algorithm (that's a link to the HTML5 spec, but this is old, old behavior)
T.J. Crowder
+1  A: 

Aren't you supposed to append the form to body before you can submit it? Not sure how it works in Chrome without that, but try doing something like this-

$('<form/>', {
    action: "...",
    method: "...",
    style: "...",
})
.appendTo("body")
.submit();
Chetan Sastry
Thanks Chetan. That worked!
Jitesh