.net mvc中禁用客户端验证

.net mvc中使用HtmlHelper或TagHelper会在HTML控件和生成验证属性,比如下面的红色部分

 <input type="radio" title="显示" value="1" checked="checked" data-val="true" data-val-required="The viptype field is required." id="viptype" name="viptype" />

这是.NET MVC的客户端验证代码,但大多数时候我是用不到的
在.net framework中,

web.config应用程序级配置

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

编程方式

 protected void Application_Start() 
{
//Enable or Disable Client Side Validation at Application Level
HtmlHelper.ClientValidationEnabled = true;
HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
} 

特定视图

 @model MvcApp.Models.Appointment
@{
ViewBag.Title = "Make A Booking";
HtmlHelper.ClientValidationEnabled = false;
}

.net core

builder.Services.AddMvc().AddViewOptions(options =>
            {
                options.HtmlHelperOptions.ClientValidationEnabled = false;
            });

  

posted @ 2023-02-15 10:19  拼博之路  阅读(49)  评论(0编辑  收藏  举报