In Chapter 8 Ajax ActionLink, at page 197, I struggled for hours to get the Ajax.ActionLink to show my partial view inside the Index page.
Problem:
The PartialView was always displayed as its own page.
Story:
I am using the downloaded complete MVC3 version of the MvcMusicStore to walk through the books exercises.
What I did first (as per instructions in the book) was to add the script src in the bottom of my _Layout page like this.
Code:
<script src="@Url.Content("~/Scripts/jquery-2.0.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
@RenderSection("scripts", required: false)
</body>
</html>
For some reason this just wouldnât work and after a couple of hours with different changes, tests and searching on goggle
I found a page* with the (almost) same instructions and copied the following unobtrusive row to my code, just in case I had a typo in mine.
Code:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
The only difference was that this is not the minimized version, and using this instead actually (surprisingly) worked.
Solution:
Make sure that you use the full unobtrusive script as below.
Code:
<script src="@Url.Content("~/Scripts/jquery-2.0.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
@RenderSection("scripts", required: false)
</body>
</html>
Before I got this to work I did set up an identical test using a new MVC4 Project and it worked as it should,
so I thought that it could be a corrupted jQuery script and copied the known working âunobrousive-ajaxâ files to my MVC3 project, with no luck.
Probably there is a bug in the minimized version and you will need to use the full version.
Please update me on this if this is not true.
I hope this is helpful to someone else.
//Jimi
newsweb.se
* http://stackoverflow.com/questions/7...295909#7295909