I’m right now setting up a web application based on ASP.NET MVC 3 Razor. It’s going to fetch its content mainly by Ajax. The site menu is built by a mvc sitemap provider and uses Ajax.ActionLink to create and hook up the click events. That’s already working like a charm.
The menu is part of a shared layout. The layout shall be used only once – when the application is being loaded into the browser (also known as landing page, ‘Index’ of the default controller, referred to as “Home” as of now).
The default controller returns a view with the default layout containing the menu. In the menu there is also a link to “Home”. Every link in the menu aside from the link to “Home” is also working like a charm by now.
The link to the landingpage however returns Ajax content containing another instance of the menu because it is part of its layout.
So how do I distinguish between a full page request (the user enters the url into the address line of the browser or clicks an external link to my “Home”) and provide a full view and an internal ajax request and just provide a partial view of the “Home” page content?
Thanks!
You can use this extension method in your controller: IsAjaxRequest