惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
腾讯CDC
P
Privacy International News Feed
Webroot Blog
Webroot Blog
J
Java Code Geeks
爱范儿
爱范儿
A
About on SuperTechFans
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
Forbes - Security
Forbes - Security
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
量子位
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 聂微东
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs

博客园 - 赶路人之刚出发

集成WebSecurity的Authorize进行身份验证时,数据库连接报错问题 Html.ActionLink传递参数 Automapper结合EF实现insert,update方法 Html.RenderPartial WebMatrix.WebSecurity创建自定义用户属性 强类型view中List<Model〉问题 ViewBag任意属性的实现方法 params关键字 配置LINQ中的datacontext的log路径,以记录datacontext执行了的查询sql SortedList LINQ join/left join/cross join/group by/group join/sortedlist/cast Linq to objects示例 yield return 和 Func Lamda表达式 IDisposable 匿名类型与扩展方法 对象初始化器和集合初始化器 C#自动属性 .net random伪随机数
MVC中使用RemoteAttribute异步远程验证
赶路人之刚出发 · 2013-05-09 · via 博客园 - 赶路人之刚出发

使用方法:

1。Model中增加Remote Attribute,并指定相应的验证Action路径

 public class UsingRemote
    {
         [Required]
           [Remote("IsNumberEven", "GuestBook", ErrorMessage = "数字必须是偶数!")]
           public int EvenNumber { get; set; }
    }

IsnumberEven为Action,GuestBook为Controller

2。Controller中创建相应验证方法:

     [HttpGet]
        public JsonResult IsNumberEven(int EvenNumber)
        {
            return Json(EvenNumber % 2 == 0, JsonRequestBehavior.AllowGet);
        }

注意:必须为[HttpGet],返回结果必须为Json

3.View中添加元素:

@using Mvc4Application.Models
@model UsingRemote
@{
    ViewBag.Title = "RemoteAttribute";
}
@{Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript();}

<h2>RemoteAttribute</h2>
@using (Html.BeginForm("RemoteAttribute", "GuestBook"))
{
    @Html.EditorForModel()                             
    <button type="submit">submit</button>                          
}

注意:因为Remote实际为通过调用JQuery实现的异步远程调用,所以必须在_layout.cshtml中同时引用了如下三个文件:

   <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" 
               type="text/javascript"></script>
         <script src="@Url.Content("~/Scripts/jquery.validate.js")" 
               type="text/javascript"></script>
         <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" 
               type="text/javascript"></script>

且在该view中声明了:

@{Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript();}

或在web.config中声明:

 <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>