



























.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;
});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。