Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Check out the _Root.cshtml in Alloy project for some examples. For smaller changes you can just pass the partial view a model like
Html.RenderPartial("Header", Model);
for Alloy the use a viewmodel that contains both the current page and some general layout info.
@model IPageViewModel<SitePageData>
If you just have a few presentation details like formatting title differently that you want to modify, you can probably implement that in your partial view depending on what type the current page is (that is passed in through the model above) and page name etc. If you need more control like fetching from external datasource or similar I would probably extend the viewmodel with a separate field and fill that in the controller and then pass it in.
Alloy uses a layout view model like
public class LayoutModel { public SiteLogotypeBlock Logotype { get; set; } public IHtmlString LogotypeLinkUrl { get; set; } public bool HideHeader { get; set; } public bool HideFooter { get; set; } public LinkItemCollection ProductPages { get; set; } public LinkItemCollection CompanyInformationPages { get; set; } public LinkItemCollection NewsPages { get; set; } public LinkItemCollection CustomerZonePages { get; set; } public bool LoggedIn { get; set; } public MvcHtmlString LoginUrl { get; set; } public MvcHtmlString LogOutUrl { get; set; } public MvcHtmlString SearchActionUrl { get; set; } }
that you can extend to your hearts content
Hi Nathan,
If you just want to pass string (or any other object) to the view using Html.Partial helper, you can do it like this:
Head.cshtml
@{ var additionalInfo = ViewBag.additionalInfo as string; } @* Rest of the code *@ @if (!string.IsNullOrEmpty(additionalInfo)) { <p>Additional info: @additionalInfo</p> }
Index.cshtml (or any other view)
@Html.Partial("Head", Model, new ViewDataDictionary { { "additionalInfo", "Lorem ipsum dolor"} })
Hope this helps!
The way our sites are being set up, all pages use a shared head.cshtml view for all things head. For a couple of page types, they will need some additional info in the page title tag than standard pages get. So, for those pages' layout view, which calls the head using a partial...
I'd like to pass in additional text to the title tag.
I hope that makes sense. Is this possible and if so, how? Thanks!