c# - Handling form submit event -


i have following form:

@using (html.beginform(new { returnurl = viewbag.returnurl, @class = "form-vertical login-form", id = "loginform" }))                      <button type="submit" class="btn green pull-right">                         login <i class="m-icon-swapright m-icon-white"></i>                     </button>  } 

and javascript handling event function

$(document).ready(function () {              $("#loginform").submit(function () {                 alert('handler .submit() called.');                 return false;             }); } 

however doesn't work @ all.

the alert never triggered

that's normal, never assigned form id or class. @ generated html in browser understand mean.

you using wrong overload of beginform helper.

try instead:

@using (html.beginform(null, null, new { returnurl = viewbag.returnurl }, formmethod.post, new { @class = "form-vertical login-form", id = "loginform" })) {     <button type="submit" class="btn green pull-right">         login <i class="m-icon-swapright m-icon-white"></i>     </button> } 

now please read different beginform overloads on msdn , compare yours mine.

as can see there's difference between routevalues parameter , htmlattributes parameter.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -