Copied to clipboard

Flag this post as spam?

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


  • George 58 posts 165 karma points
    Dec 30, 2019 @ 08:14
    George
    0

    Converting masterpages to MVC

    We are running Umbraco 7.10.3. We read that upgrading to version 8+ will make master page templates unusable. We want to convert our master pages to MVC razor views in order to make upgrading Umbraco possible. Let's say we have the following templates in Umbraco where 3. inherits 2. and 2. inherits 1. :

    1. 'DefaultMaster' -> 2. 'Navigation - ProductList' -> 3. ProductList

    Each of those template has a corresponding .master file in the masterpages folder.

    1. Do we just need to create a view with a name identical to the masterpage in the Views folder in order to switch?
    2. The actual file corresponding to the template 'Navigation - ProductList' is called 'NavigationProductList.master'. How do we deal with badly named templates/master pages and their children?
    3. The actual Umbraco pages each have a template associated with them. If we change from master pages to Views, do we need to go through all Umbraco pages and change the templates as well?

    Any additional links/tips/info/considerations for converting master pages to MVC Views will be greatly appreciated too!

  • Marc Goodson 1775 posts 11833 karma points MVP 7x c-trib
    Dec 30, 2019 @ 21:27
    Marc Goodson
    100

    Hi George

    We used to cover this on the old Umbraco Level 2 training course, when MVC was first introduced.

    There is a setting in umbracoSettings.config called defaultRenderingEngine...

    change this to be MVC

    <​defaultRenderingEngine​>​Mvc​</​defaultRenderingEngine>
    

    What this means is that when you create a new template in your Umbraco implementation it will create an MVC View instead of a Masterpage.

    To replace a Masterpage with a View - create a .cshtml file in the /views folder with the same name as the .master file you are looking to convert.

    When a request comes in for a document type based on that template, Umbraco will first look for the View in the Views folder matching the alias of the template, and then if that doesn't exist, fallback to look for the Masterpage. (the idea is you could migrate over time, template by template)

    So if you have a ProductList template that has an existing Masterpage called productlist.master then create a corresponding /views/productlist.cshtml and Umbraco will automatically use that over the Masterpage, without having to change templates etc.

    I had a cheatsheet for converting Masterpages to Umbraco V7 that we used to give out on the course - but the syntax is different again for V8!! http://tooorangey.co.uk/media/1169/umbraco-masterpages-to-views-conversion-cheat-sheet.pdf

    But in terms of your 'inheritance' structure, your MVC view has a 'Layout' option that specifies the 'MVC' view that the layout is inherited from, so you could have a MVC view called DefaultMaster.cshtml with Layout set to Null eg

    @{
      Layout = null;
    }
    

    and then you could have a NavigationProductList.cshtml which inherits from the DefaultMaster

    @{
      Layout = "DefaultMaster.cshtml";
    }
    

    and then your ProductList.chstml could inherit it's layout from NavigationProductList..

    @{
      Layout = "NavigationProductList.cshtml";
    }
    

    just like masterpages.. except you use @section instead of <asp:content

    With UserControls, it depends on the functionality you have inside them, eg if they are just writing out content, then PartialViews or Macros implemented with a PartialView are the equivalent. If they contain Form Fields, then the equivalent is to use a SurfaceController, to handle post backs... https://our.umbraco.com/Documentation/Reference/Routing/surface-controllers

    regards

    Marc

  • AddWeb Solution Pvt. Ltd 109 posts 354 karma points
    Dec 31, 2019 @ 05:01
Please Sign in or register to post replies

Write your reply to:

Draft