开发者

MVC ajax not working

开发者 https://www.devze.com 2023-03-23 23:00 出处:网络
I have this code in my .cshtml: <script src=\"../../Scripts/MicrosoftAjax.js\" type=\"text/javascript\"></script>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号