Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Building on @Darin-Dimitrov pattern answered above, I passed a model into a partial view, which I loaded into a _Layout page.</p> <p>I needed to load a web page from an external resource on Application Load, which will be used as the header navigation across multiple sites. This is in my Global.asax.cs</p> <pre><code>protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); Application["HeaderNav"] = GetHtmlPage("https://site.com/HeaderNav.html"); } static string GetHtmlPage(string strURL) { string strResult; var objRequest = HttpWebRequest.Create(strURL); var objResponse = objRequest.GetResponse(); using (var sr = new StreamReader(objResponse.GetResponseStream())) { strResult = sr.ReadToEnd(); sr.Close(); } return strResult; } </code></pre> <p>Here is my controller Action for the partial view.</p> <pre><code>public class ProfileController : BaseController { public ActionResult HeaderNav() { var model = new Models.HeaderModel { NavigationHtml = HttpContext.Application["HeaderNav"] as string }; return PartialView("_Header", model); } } </code></pre> <p>I loaded the partial view in the _Layout page like this.</p> <pre><code>&lt;div id="header"&gt; @{Html.RenderAction("HeaderNav", "Profile");} &lt;/div&gt; </code></pre> <p>The partial view _Header.cshtml is very simple and just loads the html from the application variable.</p> <pre><code>@model Models.HeaderModel @MvcHtmlString.Create(Model.NavigationHtml) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload