1,问题
在mvc验证的时候怎么自定义验证action?比如说验证用户名是否重复。
2.解决方法
通过remote 的特性
第一参数是对应的action 第二个对应的是controller
controller 中的的方法
public JsonResult CheckUserName(
string userName)
{
if (IsUniqueName(userName) &&
IsForbiddenName(userName))
{
return Json(
true, JsonRequestBehavior.AllowGet);
}
else if (!
IsUniqueName(userName))
{ // 自定义errorMessage
return Json(
"用户名不唯一!", JsonRequestBehavior.AllowGet);
}
else
{
return Json(
"用户名不包含违禁词!", JsonRequestBehavior.AllowGet);
}
}
通过返回 true.
转载于:https://www.cnblogs.com/damsoft/p/6082172.html
相关资源:数据结构—成绩单生成器