Copied to clipboard

Flag this post as spam?

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


  • Terry Clancy 204 posts 944 karma points
    Feb 25, 2016 @ 06:58
    Terry Clancy
    0

    Add custom / shared location to the Umbraco View Engine default search patterns

    Hi all,

    I have various MVC views associated with various controllers.

    Each view is in a folder with the name of the Controller (without "controller") .

    All those views need to use the SAME "Master.cshtml" layout file. That file is currently located in ~/Views/

    This is not normally an issue because in general my MVC pages are included in normal Umbraco pages as Partial Views and the Normal Umbraco page takes care of referencing the "Master.cshtml" layout file.

    However for some pages such as http://www.mysite.com/users/Myusername I use Custom MVC Routes as described at https://our.umbraco.org/documentation/reference/routing/custom-routes.

    In the case of pages using Custom MVC Routes I return from the controller as follows to indicate the name of the Master layout file:

    return View("ViewProfile", "TTMaster", viewProfileViewModel);
    

    But my ~/Views/Master.cshtml is not found.

    I tried the approach detailed at http://www.ryadel.com/en/asp-net-mvc-add-custom-locations-to-the-view-engine-default-search-patterns/ but as indicated by my comments at the bottom of that page it did not work, it appears this is because that neither of the following work in Umbraco whereas it does in a standard ASP.Net MVC app:

    var razorEngine = ViewEngines.Engines.OfType<razorviewengine>().First();
    

    or

    string EngineName = ViewEngines.Engines[x].ToString();
    

    Can you please help me with the best way to resolve this without resorting to Multiple duplicative Master.cshtml files ?

    Thanks

    Terry Clancy

    ClanceZ

  • Troels Larsen 75 posts 280 karma points
    Feb 25, 2016 @ 08:22
    Troels Larsen
    0

    Hey Terry

    Mvc has a concept Called Shared views and all i have to do is create a folder Called Shared in your views folder an put i Master there

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 25, 2016 @ 10:57
    Dave Woestenborghs
    0

    Why don't you put a layout directive in you view it self ?

    @{
        Layout = "_Master.cshtml";
    }
    

    Like this ?

    Dave

  • Troels Larsen 75 posts 280 karma points
    Feb 25, 2016 @ 11:59
    Troels Larsen
    0

    And u can use _ViewStart.cshtml to add (should allso be placed in ~/views/Shared/)

    @{
        Layout = "_Master.cshtml";
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft