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. :
Each of those template has a corresponding .master file in the masterpages folder.
Do we just need to create a view with a name identical to the masterpage in the Views folder in order to switch?
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?
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!
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.
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
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. :
Each of those template has a corresponding .master file in the masterpages folder.
Any additional links/tips/info/considerations for converting master pages to MVC Views will be greatly appreciated too!
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
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
and then you could have a NavigationProductList.cshtml which inherits from the DefaultMaster
and then your ProductList.chstml could inherit it's layout from NavigationProductList..
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
Hello George,
Check this out
https://our.umbraco.com/documentation/cheatsheets/masterpagestoviews
is working on a reply...