ASP.NET MVC 使用Remote特性实现远程属性验证
2017-09-12 22:20
791 查看
RemoteAttribute是asp.net mvc 的一个验证特性,它位于System.Web.Mvc命名空间
View Code
这里调用了Html.EnableClientValidation(); 和Html.EnableUnobtrusiveJavaScript(); 同时引入jquery.validate.js 和jquery.validate.unobtrusive.js
前台浏览,并填写信息
当填写存在的用户名和手机号码时
上面例子是基于ASP.NET MVC 5
@model RemoteDemoWeb.Models.Member @{ ViewBag.Title = "Create"; Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript(); } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Member</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Mobile, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Mobile, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> @section scripts{ <script src="~/Scripts/jquery.validate.js"></script> <script src="~/Scripts/jquery.validate.unobtrusive.js"></script> }
View Code
这里调用了Html.EnableClientValidation(); 和Html.EnableUnobtrusiveJavaScript(); 同时引入jquery.validate.js 和jquery.validate.unobtrusive.js
前台浏览,并填写信息
当填写存在的用户名和手机号码时
上面例子是基于ASP.NET MVC 5
相关文章推荐
- ASP.NET MVC 使用Remote特性实现远程属性验证
- asp.net mvc 远程校验Remote属性在Area下验证路径不正确的解决
- ASP.NET没有魔法——ASP.NET MVC使用Oauth2.0实现身份验证
- ASP.NET没有魔法——ASP.NET MVC使用Oauth2.0实现身份验证
- 在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证
- 基于ASP.NET MVC Remote验证的AdditionalFields与checkbox搭配使用的BUG
- 使用 ExtJS 实现 ASP.NET MVC 2 客户端验证
- ASP.NET MVC使用Filter实现页面验证与授权
- asp.net mvc使用validate.js验证 若name属性包含特殊字符则加上双引号即可
- 在ASP.NET MVC Framework中使用IErrorDataInfo接口实现验证(翻的)
- ASP.NET MVC 中使用Spring.NET实现简单的属性注入
- ASP.NET MVC使用Oauth2.0实现身份验证
- 深入ASP.NET MVC Model验证-使用.NET验证特性类指定Mode验证规则
- 使用 ExtJS 实现 ASP.NET MVC 2 客户端验证
- Asp.net MVC 远程验证(Remote)的深究
- ASP.NET MVC使用Oauth2.0实现身份验证
- asp.net mvc Remote远程验证
- Asp.net MVC中表单验证属性的使用
- 在Asp.Net MVC中实现RequiredIf标签对Model中的属性进行验证
- ASP.NET MVC5+MySql使用ASP.NET 身份验证实现用户和角色功能 1 概述 目标:使用MySql数据库,建立一个使用ASP.NET 身份验证的应用,并实现角色功能,身份