Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 738 karma points
    Jul 21, 2011 @ 04:15
    Tom
    0

    Model not being carried through to render page?

    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)
      }
      else
      {
        @Html.Raw(Model.pageTitle " | Company Name")
      }
    }
    else
    {
      @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>

    and

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

     

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

  • Alex 135 karma points
    Jul 21, 2011 @ 09:31
    Alex
    0

    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.

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft
Our.umbraco.org is the community mothership for Umbraco, the open source asp.net cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community.