x First time here? Check out the FAQ
  • Avatar580posts713karma

    Model not being carried through to render page?

    Tom started this topic July 21, 2011 @ 04:15, Go directly to the topic solution

    Hi Guys,

    just trying to do the following I have a cshtml page called PageTitle.cshtml it's contents are:

    @if (@Model.pageTitle != null)

      if(Model.pageTitle.ToString().EndsWith("| Company Name"))
        @Html.Raw(Model.pageTitle " | Company Name")
      @Html.Raw(Model.Name " | Company Name")


    and then in my template am calling it like so:

    <title><umbraco:Macro runat="server" language="cshtml">@using umbraco.MacroEngines;@RenderPage("/macroScripts/PageTitle.cshtml");</umbraco:Macro></title>


    <meta property="og:title" content="@RenderPage("/macroScripts/PageTitle.cshtml")" />


    unfortunately @Model.pageTitle is not being picked up..

  • Alex posted this reply July 21, 2011 @ 09:31

    You can't use @RenderPage directly in your template (like you have done in the meta tag) because the Template page is not a Razor cshtml file.

    Also, you can reference a cshtml file directly from a Macro tag without calling RenderPage, like this:

    <umbraco:Macro FileLocation="~/macroScripts/PageTitle.cshtml" runat="server" />

    Hope that helps.


Please login or Sign up To post replies