Question

I know how to customize a controller/view template for an MVC project. However, I have a few different MVC 3 Areas in my project and each Area has its own Models, Views and Controllers. Is there a way to specify different code templates for each Area? I tried to place a CodeTemplates folder in one of my Area sub folders but it didn't work.

The idea is, when I right click on any Controller folder in an Area and select Add -> Controller, I want it to use that Area controller template.

UPDATE: I will be happy with being able to select the controller template I want to use, but still wondering if it is possible to specify CodeTemplates for the different areas.

Was it helpful?

Solution

Looks like MVC Scaffolding might be my only option here. I will show specific solution when I get it working.

OTHER TIPS

Rereading you question, I realized my answer may not be what you are trying to do. Do you wan't the auto generated code in the view to use a different template? Or did you wan't the page to look differently, like with css changes, etc? My answer applies to the latter. If you want to use different code templates, it seems like (according to this) as long as you give them different names you should be able to select the one you wan't to use. You could also probably just remove the ones you don't want from the project then add them back later.

Create 2 files in the folder you want the template to be applied to, one named _ViewStart.cshtml and the other _Layout.cshtml

In the _ViewStart file, add this:

@{
    Layout = "~/Views/Reports/_Layout.cshtml";
}

This will point to the _Layout so change the path as needed. In the _Layout file add whatever you want, just like the layout in the Shared directory. And for any other folder you want to use this layout, just add the _ViewStart file to that directory and point it to the _Layout file you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top