0
我查看:遠程驗證不行
@model MvcApplication2.Models.HomeModel
@{
ViewBag.Title = "Home";
}
<h2>Home</h2>
<a>Witaj</a>
@Model.UserName
@using (Html.BeginForm())
{
<a>Podaj hasło</a>
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(x => x.Password)
<input type="submit" />
}
和控制器
using System.Web.Mvc;
using System.Web.UI;
using MvcApplication2.Models;
namespace MvcApplication2.Controllers
{
[OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
public class HomeController : Controller
{
public ActionResult Index()
{
HomeModel model = new HomeModel() { UserName = "John" };
return View(model);
}
public JsonResult CheckPassword(string password)
{
bool result = false;
if (password.Length < 4)
{
result = false;
}
else
{
result = true;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
}
}
和型號:
using System.Web.Mvc;
namespace MvcApplication2.Models
{
public class HomeModel
{
public string UserName { get; set; }
[Remote("CheckPassword", "Home", ErrorMessage = "Wpisz lepsze hasło")]
public string Password { get; set; }
}
}
當應該遠程驗證方法火?當我點擊輸入按鈕?我做錯了什麼?
解決方案找到[這裏] [1] - 需要設置在web.config中 [1]:http://stackoverflow.com/questions/19680967 /遠程attribue驗證 - 不點火式-ASP淨MVC – netmajor