Remove Validation in ASP.NET MVC 3
Posted
by
johndoe
on Stack Overflow
See other posts from Stack Overflow
or by johndoe
Published on 2011-01-06T15:50:01Z
Indexed on
2011/01/06
15:54 UTC
Read the original article
Hit count: 191
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);
}
© Stack Overflow or respective owner