[Required]
[Display(Name= "用户名")]
[Remote("CheckUsn", "User", ErrorMessage="用户名已存在!")]
public string Usn { get; set; }第二步:在Controller中添加指定的Action:
using System;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class UserController : Controller
{
public ActionResult CheckUsn(string Usn)
{
bool result = !Usn.Equals("admin", StringComparison.CurrentCultureIgnoreCase);
return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
}说明:Action返回格式必须为JSON,Action参数类型和名称必须和Model对应。
效果预览
评论(0)
暂无评论。