Yesterday, I was cursing at my new ASP.Net MVC project. I was trying to use Ajax.ActionLink to refresh the part of the page which uses Ajax. Well, it should be very straightforward but I failed due to one minor mistake… I took care of everything- I used proper call in Controller (RenderPartial), I checked 10 times if I passed the correct div id, I debugged it at least 20 times and still my page, after Ajax request, was rendered like it didn’t have a Site.Master code around it…
My problem – after Ajax request my page was rendered incorrectly
When I launched Ajax.ActionLink on my page, as a result I got the incorrectly rendered view. Have a look at these two pictures below:
Ajax.ActionLink – is not only C# code
In order to find out where the mistake was made I took a different example (Contact Manager from ASP.Net MVC site) and I checked once again why my Ajax.ActionLink was not working. I was really surprised to see it working there perfectly well but not working in my own project even though I followed the exact same steps… well, almost everything.
Don’t forget to include MicrosoftAjax
That was my mistake. I forgot to include two javascripts in my Site.Master page. Stupid, I know.
<script src=”../../Scripts/MicrosoftAjax.js” type=”text/javascript”></script>
<script src=”../../Scripts/MicrosoftMvcAjax.js” type=”text/javascript”></script>
What really made me angry was the fact that without these two lines everything was working, no error messages from Visual Studio! The only simple difference was that when you entered Controller method responsible for handling the Ajax Request, the IsAjaxRequest was returning false even though you used Ajax.ActionLink to launch it.
That was my yesterday lesson on how to use ASP.Net MVC. I still think that this is a really good framework. Just like Rob Conery said in his video , it is like driving a motorcycle.
Sometimes you will get bugs in your mouth. Yesterday, I ate the whole bucket of them. Feel free to leave a comment below or exchange your ideas through Twitter @GOYELLO.
[amazonify]::omakase::468:60[/amazonify]
<script src=”../../Scripts/MicrosoftMvcAjax.js” type=”text/javascript”></script>
Thanks a lot for article. I've made the same mistake.
ive seriously spent all day banging my head against my keyboard and searching for every example in existence. i wish i found this one first.
That was my hope. I wanted to post about this stupid bug and I am happy that I helped you!
It looks good,I have learn a recruit!
Recently,I found an excellent online store, the XX are completely various, good quality and cheap price,it’s worth buying!
Hhe article's content rich variety which make us move for our mood after reading this article. surprise, here you will find what you want! Recently, I found some wedsites which commodity is research-laboratory colorful of fashion. Such as that worth you to see. Believe me these websites won’t let you down.
I get the same error with you but I still have no glue for it. I have even insert MicrosoftAjax and MicrosoftMvcAjax already
Wow! That worked for us as well.