asp.net mvc - Model View Remote Validation -


i doing remote validation using remote attribute in mvc model, please find code below:

[required] [system.web.mvc.remote("isemailexist", "account", httpmethod = "post", errormessage = "the email exists")] 

in controller action method use user input of email parameter , check db, please find code below:

public jsonresult isemailexist(string emailaddress) {     using  (var db = new youtubenz())                                                     {          var isexist = !db.users.any(x => x.emailaddress == emailaddress);                                                  return json(isexist, jsonrequestbehavior.allowget);                                                      } }               

but during run time parameter in action method "null" when value should user input email address , not getting validated existing email.

make sure decorate action method httppost attr, , property name matches method parameter (i.e: emailaddress):

[httppost] public jsonresult isemailexist(string emailaddress) {     using  (var db = new youtubenz())                                                     {          var isexist = !db.users.any(x => x.emailaddress == emailaddress);                                                  return json(isexist, jsonrequestbehavior.allowget);                                                      } } 

Comments