Remove Validation in ASP.NET MVC 3
- by johndoe
I am trying to get remote validation working in ASP.NET MVC 3 but for some reason the validation never gets fired. I am returning json from the controller and in FireFox it ask me to download the files. Not sure what is going on here. Here is my code:
@using(Html.BeginForm(new {Action = "ValidateUserName"})) {
<text> Enter UserName: </text> @Html.TextBoxFor(x => x.UserName)
<input type="submit" value="Login" />
}
Here is the RegistrationViewModel:
public class RegistrationViewModel
{
[Required(ErrorMessage = "UserName is required!")]
[Remote("ValidateUserName","Home",ErrorMessage ="UserName already taken!")]
public string UserName { get; set; }
}
And here is the HomeController:
public ActionResult ValidateUserName(RegistrationViewModel registrationViewModel)
{
return Json(!registrationViewModel.UserName.Equals("test"),JsonRequestBehavior.AllowGet);
}