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
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.