如何禁用客户端验证了一个观点? [英] How to disable client-side validation for a single view?

查看:100
本文介绍了如何禁用客户端验证了一个观点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要禁用客户端验证用于在单一视图的形式。

我如何做到这一点?

我不希望只是禁用以下JS文件:

 <脚本的src =@ Url.Content(〜/脚本/ jQuery的/ jquery.validate.min.js)TYPE =文/ JavaScript的>&LT ; / SCRIPT>
<脚本的src =@ Url.Content(〜/脚本/ jQuery的/ jquery.validate.unobtrusive.min.js)TYPE =文/ JavaScript的>< / SCRIPT>


解决方案

布拉德威尔逊描述了这个在他的博客文章:<一href=\"http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html\">http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html - 我强调,从博客文章回答您的问题(最后一行)在以下报价位:


  

要打开/关闭非侵入式JavaScript模式,并默认启用整个应用程序/禁用客户端验证,可以使用Web.config文件:

 &LT;结构&gt;
    &LT;&的appSettings GT;
        &LT;添加键=ClientValidationEnabledVALUE =真/&GT;
        &LT;添加键=UnobtrusiveJavaScriptEnabledVALUE =真/&GT;
    &LT; /的appSettings&GT;
&LT; /结构&gt;

您也可以将其打开或关闭code:

  HtmlHelper.ClientValidationEnabled = TRUE;
HtmlHelper.UnobtrusiveJavaScriptEnabled = TRUE;


  
  

使用code打开或关闭行为实际上这些功能
  上下文。如果code这些线在你的Global.asax present
  文件,然后打开不显眼的JavaScript和客户端验证或
  关闭整个应用程序。 如果它们出现在你的
  控制器或视图,在另一方面,这将打开的特征或
  关闭仅当前操作。


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:

<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>

解决方案

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:

To turn unobtrusive JavaScript mode on/off and enable/disable client validation by default for the entire application, you can use 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.

这篇关于如何禁用客户端验证了一个观点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆