Using cshtml template template

When I create my controller and views with the following command

scaffold controller <Entity> -force -repository -DbContextType "XXX" -Area YYY 

It creates .aspx pages (web form) instead of .cshtml (razor)

How to change this default behavior. I think when I first created a new project, he asked me to choose the default view mechanism, and I chose the wrong one (web forms).

There are also free or cheap T4 templates for MVC 3 that generate more convenient and functional presentations. using webgrid / jquery etc.

+6
source share
1 answer

The wide lattice solution configuration is stored in scaffolding.config , which is located in the same folder with the solution file.

At the stage of installing MvcScaffolding , the init.ps script package is init.ps (you can find it in the <packages folder>\MvcScaffolding.<version>\tools directory). The script calculates aspx , cshtml and vbhtml views, and based on these numbers it is determined which kind of scaffolder will be used. Here is a snippet of this logic:

 function InferPreferredViewEngine() { # Assume you want Razor except if you already have some ASPX views and no Razor ones if ((CountSolutionFilesByExtension aspx) -eq 0) { return "razor" } if (((CountSolutionFilesByExtension cshtml) -gt 0) -or ((CountSolutionFilesByExtension vbhtml) -gt 0)) { return "razor" } return "aspx" } # Infer which view engine you're using based on the files in your project $viewScaffolder = if ([string](InferPreferredViewEngine) -eq 'aspx') { "MvcScaffolding.AspxView" } else { "MvcScaffolding.RazorView" } Set-DefaultScaffolder -Name View -Scaffolder $viewScaffolder -SolutionWide -DoNotOverwriteExistingSetting 

So, you can switch the scaffolder view using the following commands:

 Set-DefaultScaffolder -Name View -Scaffolder "MvcScaffolding.RazorView" -SolutionWide Set-DefaultScaffolder -Name View -Scaffolder "MvcScaffolding.AspxView" -SolutionWide 

Or you can manually edit the scaffolding.config file and replace the value for the ScaffolderName attribute in the tag:

 <Default DefaultName="View" ScaffolderName="put here either MvcScaffolding.RazorView or MvcScaffolding.AspxView" /> 
+2
source

All Articles