asp.net mvc 4 - unobtrusive ajax form prevent cancel button from posting -
question: why cancel button posting controller submit?
i have form below loaded partial view. submit works fine. thing i've been struggling why cancel doesn't dismiss form. i've tried variety of things capturing click event. looked @ http://jimmylarkin.net/post/2012/05/16/broken-validation-on-cancel-buttons-with-unobtrusive-validation-ajax.aspx possible solution i'm not sure problem it's intended address. no doubt it's ignorance on part. bonehead thing missing?
//click event loading form. <script> $(document).ready(function () { $('#editbtn').click(function () { var url = "/quiz/editquiz?id=@id"; $.get(url, function (data) { $('#formdiv').html(data); $("#formdiv").show(); }); }); </script> //form inside partial view. @using (ajax.beginform("editquiz", "quiz", formmethod.post, new ajaxoptions { insertionmode = insertionmode.replace, httpmethod = "post", updatetargetid = "formdiv" })) { @html.validationsummary(true) @html.antiforgerytoken() <div> <fieldset> . . <input type="submit" class = "btn btn-primary" value="save" /> <button class = "cancel" >cancel </button> </fieldset> </div> }
i'm curious if cancel button whats causing submit default. try replacing <button class="cancel">
html helper. how @html.actionlink("cancel", "index")
. link has text cancel
, redirects action index
.
Comments
Post a Comment