Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  46] [ 7]  / answers: 1 / hits: 48644  / 12 Years ago, wed, july 25, 2012, 12:00:00

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


More From » c#

 Answers
20

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
}
}
});
}

[#84057] Monday, July 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dawnc

Total Points: 612
Total Questions: 94
Total Answers: 98

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;