1

I have an ASP.Net MVC 4 application where the user can choose a theme or a design of for their hosted one-page site (within this application). At first, I thought to do this with the built-in Areas but due to some application restrictions I've decided not to use that method. The way I thought to do it (which so far works) is to send the user to the index action of the controller, there find out which theme they have chosen and then return the appropriate view. this way I don't have the action name on the url which is nice since the url needs to be simple like: abc.com/cb/websiteID. btw, every theme/design has one view in the folder.

For some reason this method does not sit well with me and I think there should be a better way of doing this. Is there a downfall to this? Is this method a bad practice? is there a better way?

If I've left out a detail, please let me know and I'll do my best to address it.

1 Answer 1

3

Do you have a limited set of themes, which your users can choose from? If so, I would consider to have a layout-per-theme instead, have a single view and dynamically switch layout based on params...

//in your controller
public ActionResult(int id) {
    string layoutForThemeName = SomeService.GetThemeForUser(id);
    ViewBag.LayoutName = layoutForThemeName 
}

// in your view Index.cshtml
@{
    Layout = ViewBag.LayoutName;
}

Do not forget that Razor let you inherit one layout from another, so you could event create base layout with script references etc. and layout for every of your themes.

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.