3
整個頁面

在我看來,我有:ASP.NET MVC4 Ajax.ActionLink取代

@section Header { 
    @Scripts.Render("~/bundles/jqueryval") 
} 

<div> 
    <div>@Ajax.ActionLink("Test", "CurrentTime", new AjaxOptions { UpdateTargetId = "some_div", InsertionMode = InsertionMode.InsertAfter })</div> 
</div> 

<div id="some_div"> 

</div> 

在結果頁面看到這些腳本會被引用的標題:

<script src="/Scripts/jquery-1.6.4.js"></script> 
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script> 
<script src="/Scripts/jquery.validate.js"></script> 
<script src="/Scripts/jquery.validate.unobtrusive.js"></script> 

的鏈接看起來有像這樣:

<div><a data-ajax="true" data-ajax-mode="after" data-ajax-update="#some_div" href="/Tournament/CurrentTime">Test</a></div> 

在控制器:

public string CurrentTime() 
{ 
    return DateTime.Now.ToLongTimeString(); 
} 

在我的web.config(在應用程序的根目錄):

<add key="ClientValidationEnabled" value="true" /> 
<add key="UnobtrusiveJavaScriptEnabled" value="true" /> 

我的問題是:每當我點擊鏈接,結果(當前時間)總是會替換整個頁面 - 這是不在some_div之前/之後插入。 感謝

+0

請在chrome或firefox中查看錯誤控制檯。可能你的腳本沒有加載 – 2013-05-03 19:00:43

+0

@Garath:謝謝!螢火蟲發現這一點: 類型錯誤:$(...)就不是一個函數 \t 的$(document)。在( 「點擊」, 「一個[數據阿賈克斯=真]」,函數(EVT ){ 但我沒有編輯腳本(至少我不知道這一點)。我請應如何解決呢?這是jquery.unobtrusive Ajax的文件。謝謝 – 2013-05-03 19:18:24

回答

1

基礎上您的評論的答案很簡單,你必須升級你的jQuery。 on方法從jquery 1.7開始工作。我建議使用jQuery 1.7.2,因爲mvc腳本有時會出現更高版本的問題

+0

非常感謝,現在它的工作原理。有沒有機會使用jquery.unobtrusive-ajax和更新版本的jQuery? – 2013-05-04 06:22:03

+0

你可以看看這裏http://stackoverflow.com/questions/14391867/unobtrusive-ajax-stopped-working-after-update-jquery-to -1-9-0。 – 2013-05-04 06:44:00

+0

有一個jquery驗證的更新https://nuget.org/packages/jQuery.Validation/1.11.0 – 2013-05-04 07:50:37