I have a number of themes in my MVC app. In my controller, I build a javascript literal as a string to pass to my UI charting library:

private string GetScoreChartStyles()
{
    var theme = Session["Theme"];
    if (!String.IsNullOrWhiteSpace(theme))
    {
        switch (theme)
        {
            case "green":
                return @"{
                            scoreLineColour: '#9F873F',
                            averageLineColour: '#EABF00',
                            gridBackgroundColour: '#ebe5d8',
                            gridBorderColour: '#CDC3AC'
                        }";
            case "purple":
                return @"{
                            scoreLineColour: '#007ebf',
                            averageLineColour: '#6d6d6d',
                            gridBackgroundColour: '#edf6fa',
                            gridBorderColour: '#b4b4b4'
                        }";

These styles need to passed in as a js object literal, adding this as CSS won't work. I hate having to hard code all these values in the controller...

I'm looking for a solution like Resource files, except instead of working with languages, we map based on themes.

Related posts

Recent Viewed