ASP.Net MVC – issue with Ajax.ActionLink

mvc-logoYesterday, 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:

Picture 1 My page before launching "test" link which is Ajax.ActionLink


Picture 2 My page after it. You an see that It rendered without rest of the page

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. ASPNetMVC_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/MicrosoftAjax.js” type=”text/javascript”></script>
<script src=”../../Scripts/MicrosoftMvcAjax.js” type=”text/javascript”></script>

IT guy with head full of ideas, strongly oriented on achieving great goals in life. Currently working for GOYELLO, place where I grow.