從.NET 4.5開始,Validators使用數據屬性和有界的Javascript來完成驗證工作,所以.NET期望您爲jQuery添加一個腳本引用。
有解決錯誤兩種可能的方式:
禁用UnobtrusiveValidationMode
:
一下添加到web.config中:
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
它會工作,因爲它的工作在以前的.NET版本中,只是將必要的Javascript添加到您的頁面以使驗證器正常工作,而不是尋找f或者你的jQuery文件中的代碼。實際上這是常見的解決方案。
另一種解決方案是註冊腳本:
在Global.asax中添加Application_Start
映射到您的jQuery的文件路徑:從MSDN
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
new ScriptResourceDefinition
{
Path = "~/scripts/jquery-1.7.2.min.js",
DebugPath = "~/scripts/jquery-1.7.2.min.js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.js"
});
}
一些細節:
ValidationSettings:UnobtrusiveValidationMode Specifies how ASP.NET globally enables the built-in validator controls to use unobtrusive JavaScript for client-side validation logic.
If this key value is set to "None" [default], the ASP.NET application will use the pre-4.5 behavior (JavaScript inline in the pages) for client-side validation logic.
If this key value is set to "WebForms", ASP.NET uses HTML5 data-attributes and late bound JavaScript from an added script reference for client-side validation logic.
[ASP.Net 2012不唐突的驗證使用jQuery](的可能的複製http://stackoverflow.com/questions/12452109/asp-net-2012-unobtrusive-validation-with-jquery) – mihkov
[WebForms UnobtrusiveValidationMode需要爲'jquery'提供ScriptResourceMapping。請添加ScriptResourceMapping命名的jQuery(區分大小寫)(https://stackoverflow.com/questions/16660900/webforms-unobtrusivevalidationmode-requires-a-scriptresourcemapping-for-jquery) –