0

I'm developing a .net mvc4/5 site that presents a gui for users of third party companies. We would like to change some of the style elements on the site like the logo or some css based on what company the user belongs to.

Right now I'm saving the user belonging in a mvc Session and have created partial views for the items I like to change. In the view I'm checking the session variable and based on that I present the correct logo.

Example

@if (Session["affiliation"] != null)
{
    var affiliation = Session["affiliation"].ToString();

    if (affiliation == "Company1")
    {
        <img src="~/Content/img/logo1.png" class="navbar-logo" />
    }
    else if (affiliation == "Company2")
    {
        <img src="~/Content/img/logo2.png" class="navbar-logo" />
    }
}

This will obviously not scale. Does anyone have a better solution? Ideally I would like to base the style of the page elements on the route. So that, for instance http://www.page.com/Company1 and http://www.page.com/Company2 points to the same controller but some of the information in the view changes based on the route elements. Is this possible without creating too much clutter in the view?

1 Answer 1

1

You can use browser specific modes - essentially this isn't a different browser, just a different view.

In Application_Start

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Company1")
{
    ContextCondition = (context => return context.Session["affliation"] == "Company1"// check for user)
});

Then in your view folder, have Views/MyPage.Company1.cshtml

More info at ASP.Net/MVC under the heading Browser Specific Views

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.