Share via


WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

Question

Thursday, May 11, 2017 3:24 AM

Why does this error come up when following the instructions on msdn's website exactly?

https://msdn.microsoft.com/en-us/library/879kf95c.aspx?f=255&MSPPError=-2147217396

After testing the Login page, this error is all that shows up on Edge.

All I did was follow instructions from the site listed above ad verbatim.

All replies (1)

Thursday, May 11, 2017 7:17 PM

You may get this exception if your project is targeting 4.5 and project doesnt have a scriptResourceMapping. There are couple of solutions for this problem

if you dont have any Jquery Validation for your project then an easy fix will be to disable the validation using web.config file setting like below

<configuration>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>

However if you dont want to disable the UnObtrusive validation and still want to fix the issue the one suggestion is to add the scriptresource mapping in Global.asax page Application Start method

protected void Application_Start(object sender, EventArgs e)
{
    string JQueryVer = "1.7.1";
    ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
    {
        Path = "~/Scripts/jquery-" + JQueryVer + ".min.js",
        DebugPath = "~/Scripts/jquery-" + JQueryVer + ".js",
        CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".min.js",
        CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".js",
        CdnSupportsSecureConnection = true,
        LoadSuccessExpression = "window.jQuery"
    });
}

Source URL