2012年3月14日 星期三

ASP.NET 4.5 一使用到驗證控制項就出錯


本文使用Visual Studio 11 Beta工具
ASP.NET 4.5 Web Forms網頁一使用到驗證控制項就出錯,錯誤訊息如下:
WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).
  • 測試步驟為建立一個WebSite
image
  • 加一個網頁
image
  • 選Web Form
image
  • 加 Control

<asp:Label ID="Label1" runat="server" Text="Input Text"> </asp:Label>
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
          ControlToValidate="TextBox1" ForeColor="Red"> * </asp:RequiredFieldValidator>
      <asp:Button ID="Button1" runat="server" Text="Button" />

image
  • 按F5執行就會出錯,而且是摸不著頭緒的訊息:
image
請神孤狗不到…只好亂試
解法方法如下:
  • 加入一個Bin目錄
image
  • 在目錄中,放Microsoft.ScriptManager.jQuery.dll組件(補充:在Visual Studio 2012版本,需要在bin目錄下放入AspNet.ScriptManager.jQuery.dll組件。)
image
  • 總算可以正常執行
image

4 則留言:

91 提到...

哇!沒有內建在WebResource.axd裡面喔?
那migration真的要注意一下了...

米米貓學開發 提到...

也許是VS 11 Beta的關係,正式版也許就不會有這個問題。

匿名 提到...

您好,
後來發現到NuGet去找到AspNet.ScriptManager.jQuery安裝起來就OK了...
https://www.nuget.org/packages/AspNet.ScriptManager.jQuery

米米貓學開發 提到...

收到,又學一招,感謝~

總網頁瀏覽量