I have default ASP.NET MVC 4 Account register web form. I am trying to check if username already exist in database. If user name exist, user should be notified. For that, I am using remote validation (following this tutorial).
First of all I changed RegisterModel class:
[Required]
[Display(Name = "User name")]
[System.Web.Mvc.Remote("doesUserNameExist", "Account", HttpMethod = "POST", ErrorMessage = "User name already exists. Please enter a different user name.")]
public string UserName { get; set; }
Then I have put this into AccountController:
[HttpPost]
public JsonResult doesUserNameExist(string UserName)
{
var user = Membership.GetUser(UserName);
return Json(user == null);
}
In Register view, I have added these 2 lines:
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
When I click on "Register" button, nothing is happening: it is not forwarding to home page and not showing the error.
UPDATE: I have checked this form in chrome developer tool. It is giving 2 errors:
Uncaught ReferenceError: jQuery is not defined jquery.validate.min.js:46 (anonymous function) Uncaught ReferenceError: jQuery is not defined jquery.validate.unobtrusive.min.js:5 (anonymous function)
How to solve this problem?