English 中文(简体)
在 mvc3 中提供的无阻碍验证与默认的区别是什么?
原标题:What is the difference between unobstrusive validation and the default provided in mvc3

我读了很多关于无侵扰性验证的文章。 我试图理解在空的 MVC3 模板中视觉工作室提供什么和包括jquery. unobbrusive js 文件之间的区别( 如果有的话 ) 。 目前这是我在来源中的投入。

    <input class="input-validation-error" data-val="true" data-val-required="The Surname field is required." id="Surname" name="Surname" type="text" value="" />

这是不阻碍的验证吗?

最佳回答

您的 HTML 语法中有 < code> data- 属性, 看起来您页面被启用, 可以进行不受侵犯的客户端验证 。

With the traditional client-side validation javascript for the controls to be validated are generated at the server-side and passed on along with the HTML in the Response to the browser. Hence in addition to the HTML content there will be inline script data embedded within <![CDATA[ ]]>

However with unobtrusive client-side validation instead of emitting inline javascript, it makes use of HTML5 compatible Data attributes ASP.NET MVC 3 make use of jQuery for unobtrusive client-side validations. data- attributes will be manipulated from jQuery functions defined within jquery.unobtrusive js

默认情况下, ASP.NET MVC 3. 将关闭无侵扰模式。 要使用此模式, 您需要启用客户端验证 & amp; 不受侵扰的 javarint 验证 。

这可以在 Web. config 中设置。

<configuration>    
  <appSettings>        
    <add key="ClientValidationEnabled" value="true"/>        
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>    
  </appSettings>
</configuration>
问题回答

简短回答是 简短回答是 看上去你使用不侵扰性验证。 要更深入地了解它是什么和如何运作, 请阅读 http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html

数据*的属性和拼图在寻找这些属性时提供实际客户方执行情况。

http://complete development.blogspot.com/2011/02/unobstrusive-javascript-in-mvc-3-helps.html





相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签