Copied to clipboard

Flag this post as spam?

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


  • Timo Willemsen 2 posts 72 karma points
    Jan 12, 2016 @ 15:45
    Timo Willemsen
    0

    Combining regular MVC and Umbraco

    Hi all,

    I have an Umbraco website and I'd like to add a regular MVC page to it. So I've mapped attribute routing, so I can map to my controller actions and it all works fine.

        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            RouteTable.Routes.MapMvcAttributeRoutes();      
        }
    

    So, what I did was create a simple layout:

    @inherits UmbracoTemplatePage
    <!doctype html>
    <html>
    <head>
        <title>Website - /title>
    </head>
    <body>
        @RenderBody()
    </body>
    </html>
    

    Which works fine, only not (obviously) when I want to access the CurrentPage object, since it makes no sense to the regular MVC page.

    Only, now I'm stuck. What I'd like to do is the following:

    Create a BaseViewModel, with a couple of properties (e.q title, meta tag), which checks if they are available in Umbraco (trough CurrentPage?) or if the CurrentPage is not available takes uses a value which I set in the property:

    For example (what I'd want):

    @model BaseViewModel
    <!doctype html>
    <html>
    <head>
        <title>Website - Model.Name/title>
    </head>
    <body>
        @RenderBody()
    </body>
    </html>
    

    And something like this (makes no sense, since CurrentPage is not a property in BaseViewModel, but I don't know how to pass it to it either.

    public class BaseViewModel
    {
      public string Name
      {
        get
        {
          return CurrentPage == null ? "MyValue" : CurrentPage.Name; 
        }
    
      }
    }
    

    Thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft