MVC ajax not working
I have this code in my .cshtml:
<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 { UpdateTar开发者_开发技巧getId = "status"})
This is the method in controller:
public string ServerTime()
{
return "Server date: " + DateTime.Now;
}
When I click the hyperlink, the reponse comes on a different page i.e the DOM is not updated. Instead, I get redirected to Home/ServerTime
.
Can anybody tell me why is this happening? The script files are correctly downloaded and I checked it in Firebug.
Thanks in advance :)
asp.net mvc 3 by default uses unobtrusive ajax. So you should include script jquery.unobtrusive-ajax.min.js
, not the MicrosoftMvcAjax
ones. As the script is not included, javascript does not parse the ajax link data, so it stays as ordinary link.
Add OnSuccess method parameter in AjaxOptions
精彩评论