Is there a way to tell Razor (DNN's View Engine) to use a different Views Folder for a MVC Module?

122 Views Asked by At

I'm trying to use multiple folders for my views in a custom MVC module for DNN. The goal is to choose a theme in the module settings and then depending on the setting use a different view folder (i.e. use different cshtml files for the actions). Is there a way to tell razor that it should look up other locations first? (Can I use the ViewLocationExpander in DNN for my module?) Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

I understand that you want to have some kind of App settings and have MVC use the setting to select the View for you. I believe that is possible, but there is a simpler, lower-tech way to do it if using @RenderPage() or @RenderPartial() make sense for what you are trying to do.

So imagine you start in _index.cshtml

You could either have your files in folders and construct the path (imagine the setting is something like Path = "live" or "staging"):

  @RenderPage(myApp.Settings.Path + "/_List-Filtered.cshtml",
    title = "No filters", 
    index = myIndex
  )

Or directly modify the filename instead

@{
  string myViewname = "Person";
}
  @RenderPage("_List__" + myViewName + "--Filtered.cshtml")