2012-07-04 112 views
5

我想使用Ajax.ActionLink Html幫助器,因此我需要jquery.unobtrusive-ajax.min.js庫,但IE始終顯示此錯誤:ASP.NET MVC 3和jquery.unobtrusive-ajax.min.js

Microsoft JScript runtime error: Unable to set value of the property 'unobtrusive': object is null or undefined

我讀過的解決方案是jquery.validate.min.js和jquery.validate.unobtrusive.min.js的用法,但我就不能識別服務器端Ajax調用。

回答

20

I've read that the solution is usage of jquery.validate.min.js and jquery.validate.unobtrusive.min.js

不,這兩個腳本與jquery.unobtrusive-ajax.min.js無關。它們用於不顯眼的驗證。對於Ajax *助手,您只需要jQueryjquery.unobtrusive-ajax.min.js(包含在那個的順序中)。

所以不顯眼AJAX你需要:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> 
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 

如果你想使用不引人注目的驗證你也可以包括2個腳本之後(在THAT順序):

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> 
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

另一個非常重要的是你應該確保你已經從你的項目中刪除了任何Microsoft*.js腳本的痕跡。這些腳本已過時,從ASP.NET MVC 3開始,默認情況下不再使用。此外,確保啓用揮霍在你的web.config不顯眼的AJAX,否則系統會退回到傳統的Microsoft AJAX腳本:

<appSettings> 
    <add key="webpages:Version" value="1.0.0.0"/> 
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
</appSettings> 
+0

謝謝你的迴應。我使用這些:jquery-1.7.2.min.js,jquery.unobtrusive-ajax.min.js,jquery.validate.min.js,jquery.validate.unobtrusive.min.js,jquery-ui-1.8.20。 min.js和我已經設置了web.config,但我怎麼可以消除這個錯誤:Microsoft JScript運行時錯誤:無法設置屬性'unobtrusive'的值:對象爲null或未定義?因爲據我所知這是由於jquery.unobtrusive-ajax.min.js。 – sada

+0

不好意思。你是對的。 – sada

+2

請注意,jquery.unobtrusive-ajax.js與任何高於1.8.3的jquery版本不兼容。 jquery 1.8.3是與jquery.unobtrusive-ajax.js兼容的最新版本。 – monstro