asp.net mvc 3 - HttpPost method is not fired if the submit button is disabled -


i have view follows: demoview.cshtml

@model mvc3razor.models.usermodel @{     viewbag.title = "create";     layout = "~/views/shared/_layout.cshtml"; } <h2>     create</h2> <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (html.beginform()) {     @html.validationsummary(true)     <fieldset>         <legend>usermodel</legend>         <div class="editor-label">             @html.labelfor(model => model.username)         </div>         <div class="editor-field">             @html.editorfor(model => model.username)             @html.validationmessagefor(model => model.username)         </div>         <div class="editor-label">             @html.labelfor(model => model.firstname)         </div>         <div class="editor-field">             @html.editorfor(model => model.firstname)             @html.validationmessagefor(model => model.firstname)         </div>         <div class="editor-label">             @html.labelfor(model => model.lastname)         </div>         <div class="editor-field">             @html.editorfor(model => model.lastname)             @html.validationmessagefor(model => model.lastname)         </div>         <div class="editor-label">             @html.labelfor(model => model.city)         </div>         <div class="editor-field">             @html.editorfor(model => model.city)             @html.validationmessagefor(model => model.city)         </div>         <p>             <input type="submit" value="create" /></p>     </fieldset> } <div>     @html.actionlink("back list", "index") </div> <script type="text/javascript">     $(function () {         $('input[type="submit"]').click(function () {             $(this).attr('disabled', 'disabled');         });     }); </script> 

and controller: homecontroller.cs

[httppost]         public viewresult create(usermodel um)         {             if (!tryupdatemodel(um))             {                 viewbag.updateerror = "create failure";                 return view(um);             }              _usrs.create(um);             return view("details", um);          } 

in order prevent multiple button clicks, trying disable button once user clicks create button once create button disabled not firing httppost method.

can me out in order resolve issue?

try disabling button when form submitted , not when submit button clicked:

$("form").submit(function() {     $(this).attr("disabled", "disabled");     return true; }); 

Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -