Set Layout for Single paged application in ASP.NET MVC
<p>I'm new to MVC and trying to create a single paged application. </p>

<p>My Content in <code>_Layout.cshtml</code></p>

<pre><code>&lt;section class="content-wrapper main-content clear-fix"&gt;
    @Html.Action("Index", "MenuNavigation", "U01")

    @RenderBody()
&lt;/section&gt;
</code></pre>

<p>Note:  <code>@Html.Action("Index", "MenuNavigation", "U01")</code> is the place where I'm rendering my dynamic Navigation menu from database(will load only once from DB)</p>

<p>Below is my <code>_MainLayout.cshtml</code> that uses <code>_Layout.cshtml</code> as master page</p>

<pre><code>@{
    ViewBag.Title = "";
    Layout = "_Layout.cshtml"; 
}

&lt;div id="MainPageContent"&gt;
@RenderBody()
&lt;/div&gt;
</code></pre>

<p>Here is my <code>Home\Index</code> view will looks like</p>

<pre><code>@{
    ViewBag.Title = "Home Page";
    if (ViewBag.IsRequestFromLoginPage !=null &amp;&amp; ViewBag.IsRequestFromLoginPage)
    {
        Layout = "~/Views/Shared/_MainLayout.cshtml";
    }
    else
    {
        Layout = null;
    }
}
@Html.AntiForgeryToken()
&lt;h2&gt;Home&lt;/h2&gt;
</code></pre>

<p>here is the respective <code>Home</code> controller</p>

<pre><code>public ActionResult Index()
{
    ViewBag.IsRequestFromLoginPage = TempData[Constants.TempData.IsUserFromLogin];
    TempData[Constants.TempData.IsUserFromLogin] = false;
    return View();
}
</code></pre>

<p>When user logged-in to my site I wanted to render my <code>Home\Index</code> and load my Nav Menu(partial content) only on the first load. </p>

<p>If User select any of the menu item, I'm doing AJAX call to update the <code>MainPageContent</code> in <code>_MainLayout.cshtml</code> by this way I'm trying to create the single paged application but problem is when User refresh the page from browser URL. For example: If User is in "MyApp.com/Home" and refresh the browser it causes my application looses its _layout (render only home content) because of the <code>ViewBag.IsRequestFromLoginPage</code> check in my <code>Home</code> page. </p>

<p>Not sure is this the correct way to achieve this. Is there any alternative to do so. Any help will be appreciated. Thanks!</p>

<p>Here is how my Layout is looks like>
<a href="https://i.stack.imgur.com/Vkww4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vkww4.png" alt="My MVC Layout"></a></p>

<p>@Daniel
<a href="https://i.stack.imgur.com/j3Y0f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j3Y0f.png" alt="For Daniel reference"></a></p>