0
我想在ASP.NET MVC 3中獲得遠程驗證,但由於某種原因驗證永遠不會被解僱。我從控制器返回json,並在FireFox中要求我下載這些文件。不知道這裏發生了什麼事。這裏是我的代碼:ASP.NET MVC中的遠程驗證3
@using(Html.BeginForm(new {Action = "ValidateUserName"})) {
<text> Enter UserName: </text> @Html.TextBoxFor(x => x.UserName)
<input type="submit" value="Login" />
}
這裏是RegistrationViewModel:
public class RegistrationViewModel
{
[Required(ErrorMessage = "UserName is required!")]
[Remote("ValidateUserName","Home",ErrorMessage ="UserName already taken!")]
public string UserName { get; set; }
}
這裏是HomeController的:
public ActionResult ValidateUserName(RegistrationViewModel registrationViewModel)
{
return Json(!registrationViewModel.UserName.Equals("test"),JsonRequestBehavior.AllowGet);
}