我有這樣的代碼在我的.cshtml:MVC AJAX不工作
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<span id="status">No status</span> <br />
@Ajax.ActionLink("Server Date", "ServerTime", new AjaxOptions { UpdateTargetId = "status"})
這是控制器的方法:
public string ServerTime()
{
return "Server date: " + DateTime.Now;
}
當我點擊超鏈接時,效應初探而來的,是不同的頁面上即DOM不更新。相反,我被重定向到Home/ServerTime
。
有人可以告訴我爲什麼會發生這種情況?腳本文件已正確下載,並在Firebug中進行了檢查。
感謝提前:)
感謝它的工作!但什麼是不雅觀的阿賈克斯?如果我們不應該使用MicrosoftMvcAjax,那麼爲什麼在教程中提到它?我認爲它僅適用於MVC3。 – Jaggu
http://en.wikipedia.org/wiki/Unobtrusive_JavaScript得到了不引人注意的javascript術語的非常好的解釋。我不知道爲什麼在哪個教程中提到它。可能你錯過了asp.net mvc版本的教程。不顯眼的ajax更現代,使用更好,更輕量,所以它是默認的mvc 3。 – archil