Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.