jquery - Here i am applying model validation and I want to stop post my form but its not working -


my form code on trying:

 @using (html.beginform("contactus", "home", formmethod.post, new { id = "frmcontactus", enctype = "multipart/form-data" }))                 {                     <div class="form_style">                         @html.textboxfor(m => m.name, new { @placeholder = "name", @class = "inputtype" })                         @html.validationmessagefor(m => m.name)                     </div>                     <div class="form_style">                         @html.textboxfor(m => m.email, new { @placeholder = "email", @class = "inputtype" })                         @html.validationmessagefor(m => m.email)                     </div>                     <div class="form_style">                         @html.textareafor(m => m.message, new { @placeholder = "message", @class = "inputtype texarea", @style = "resize: none" })                         @html.validationmessagefor(m => m.message)                     </div>                     <div class="form_style">                         <input type="submit" class="inputtype sub_btn" id="btncontactus" value="submit" />                     </div>                     <input type="hidden" id="hdncontactus" value="@url.action("contactus", "home")" />                 } 

jquery ajax call script:

var url = $('#hdncontactus').val(); var name = $('#name').val(); var email = $('#email').val(); var message = $('#message').val(); $("frmcontactus").submit(function (e) {     e.preventdefault(); //prevent default form submit     $.ajax({         url: url,         data: { name: name, email: email, message: message },         success: function (data) {             showmsg(data);             return false;         },         cache: false     });      return false; }); 

here want model validation not want post form, post controller jsonresult:

 public jsonresult contactus(string name, string email, string message)     {         jsonresult result = new jsonresult();          return json(result, jsonrequestbehavior.allowget);     } 

this happening because have $("frmcontactus") instead of $("#frmcontactus"). forgot # id.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -