Custom Controller using View()

In the route that is registered in the accelerator we are adding an extra data token with name SkipAutoLayout (see last row).

In the _ViewStart.cshtml we are checking if this data token have been set, if the data token not have been set we are automatic setting the Layout for the view depend on the settings in accelerator.

From _ViewStart.cshtml

@using Litium
@using Litium.Accelerator.ContentProviders
@{
    if (ViewContext.RouteData.DataTokens["SkipAutoLayout"] == null 
        || ((bool?)ViewContext.RouteData.DataTokens["SkipAutoLayout"]).GetValueOrDefault() == false)
    {
        if (IoC.Resolve<IContentProvider>().ShowLeftColumnData)
        {
            Layout = "~/Views/Shared/_LayoutWithLeftColumn.cshtml";
        }
        else
        {
            Layout = "~/Views/Shared/_Layout.cshtml";
        }
    }
}

To be able to set the view from the controller and use litium hierarchical url routing you manually need to add the DataTokens["SkipAutoLayout"] = true before render the view.

I think if you update LitiumController with this extra override you will get your master layout to be used instead of the automatic selection. You need to inherit the LitiumController instead of the Controller in your implementation.

        protected override ViewResult View(string viewName, string masterName, object model)
        {
            RouteData.DataTokens["SkipAutoLayout"] = true;
            return base.View(viewName, masterName, model);
        }
1 Like