I need to disable client-side validation for a form on a single view.
我需要禁用单个视图中的表单的客户端验证。
How do I do this?
我该怎么做呢?
I do not want to just disable the following JS files:
我不想禁用以下JS文件:
<script src="@Url.Content("~/Scripts/jquery/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
1 个解决方案
#1
12
Brad Wilson describes this in his blog post: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html - I have highlighted the bits that answers your question (the last line) in the following quote from the blog post:
Brad Wilson在他的博客文章中描述了这一点:http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive- valides.html -我已经在博客文章的下面引用了以下几句话来回答你的问题(最后一行):
To turn unobtrusive JavaScript mode on/off and enable/disable client validation by default for the entire application, you can use Web.config:
要打开/关闭不显眼的JavaScript模式,并默认为整个应用程序启用/禁用客户端验证,可以使用Web.config:
<configuration> <appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings> </configuration>
You can also turn them on or off with code:
你也可以用代码打开或关闭它们:
HtmlHelper.ClientValidationEnabled = true; HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
Using code to turn these features on or off actually behaves contextually. If those lines of code are present in your Global.asax file, then it turns unobtrusive JavaScript and client validation on or off for the whole application. If they appear within your controller or view, on the other hand, it will turn the features on or off for the current action only.
使用代码打开或关闭这些特性实际上是在上下文环境中运行的。如果这些代码行出现在全局中。asax文件,然后它为整个应用程序打开或关闭不引人注目的JavaScript和客户端验证。如果它们出现在您的控制器或视图中,另一方面,它只会打开或关闭当前操作的特性。
#1
12
Brad Wilson describes this in his blog post: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html - I have highlighted the bits that answers your question (the last line) in the following quote from the blog post:
Brad Wilson在他的博客文章中描述了这一点:http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive- valides.html -我已经在博客文章的下面引用了以下几句话来回答你的问题(最后一行):
To turn unobtrusive JavaScript mode on/off and enable/disable client validation by default for the entire application, you can use Web.config:
要打开/关闭不显眼的JavaScript模式,并默认为整个应用程序启用/禁用客户端验证,可以使用Web.config:
<configuration> <appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings> </configuration>
You can also turn them on or off with code:
你也可以用代码打开或关闭它们:
HtmlHelper.ClientValidationEnabled = true; HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
Using code to turn these features on or off actually behaves contextually. If those lines of code are present in your Global.asax file, then it turns unobtrusive JavaScript and client validation on or off for the whole application. If they appear within your controller or view, on the other hand, it will turn the features on or off for the current action only.
使用代码打开或关闭这些特性实际上是在上下文环境中运行的。如果这些代码行出现在全局中。asax文件,然后它为整个应用程序打开或关闭不引人注目的JavaScript和客户端验证。如果它们出现在您的控制器或视图中,另一方面,它只会打开或关闭当前操作的特性。