Quantcast
Viewing all articles
Browse latest Browse all 15

passing different models to view based on razor theme engine

I’m using a pattern similar to the one here to implement a Themed View Engine.
Basically instead of having a View folder, I have a Theme folder and inside different themes: default, red, blue, green, etc. and inside each folder a View folder.

The issue I’m having now is that each one of these flavors needs to use a different Model.
For example, in my HomeController the Index action needs to return a GreenModel for the green theme, a RedModel for the red theme, etc.

A bit of pseudo code:

public ActionResult Index()
{
    if(Theme == "Green")
    {
        return View(greenModel);
    }
    else if(Theme = "Red")
    {
        return View(redModel);
    }
    ...
    else
    {
        return View(defaultModel);
    }
}

Is there a way to accomplish this, other than having multiple if statements in the controller for each action?


Viewing all articles
Browse latest Browse all 15

Trending Articles