I have a relatively small website that uses nested layouts.
The _Layout.cshtml contains the overall layout of the website;
- Header
- Menu
- Content
- Footer
I want the content to be loaded through Ajax but at the same time keep the website able to be navigable without it through URL. If I check in the controller if the call is Ajax and I return a ParvialView then it doesn’t render the _subLayout.cshtml that the view might be using. If I render it normally then it would ofcourse include the _subLayout.cshtml but also include the _Layout.cshtml.
How can I make the view load not the _Layout.cshtml when it is an Ajax call but do load the _subLayout.cshtml whilst keeping the _Layout.cshtml rendering intact for non-Ajax calls?
A little d’oh moment, I can ofcourse just do Request.IsAjaxRequest() in the _subLayout before the _Layout gets applied. Solved the issue.