Im using MVC3 architecture, c#.net. I need to compare text box content(User ID) with the database immediately when focus changes to the next field i.e., Password field. So I thought to use onblur event to the User Id field which then calls the Controller method. Can any tell me how to approach to this problem? As Im a newbie, code snippets are highly appreciated.
Thanks in Advance,
Prashanth
Here is an example. Example of your Controller Method
[HttpPost] // can be HttpGet
public ActionResult Test(string id)
{
bool isValid = yourcheckmethod(); //.. check
var obj = new {
valid = isValid
};
return Json(obj);
}
and this would be your javascript function.
function checkValidId(checkId)
{
$.ajax({
url: 'controllerName/Test',
type: 'POST',
contentType: 'application/json;',
data: JSON.stringify({ id: checkId }),
success: function (valid)
{
if(valid) {
//show that id is valid
} else {
//show that id is not valid
}
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With