Configure Scaffold to generate classes

2

How can I configure Scaffold to generate non-standard classes (Controllers and Views)?

    
asked by anonymous 05.10.2015 / 13:42

1 answer

2

Yes.

First you need to generate a template for your ViewModels . There is a NuGet package that has several templates as an example.

Once you've done this, modify a View template (save with another name) and code everything you'd like to have in your ViewModel . Do not forget to change the output extension of:

<#@ output extension=".cshtml" #>

To:

<#@ output extension="cs" #>

To run your Scaffold , right-click the ViewModels directory, Add > New Scaffolded Item ....

On the next screen, choose Common > MVC > View.

  

See that step is a hoot, just because the package I was going to use was bugged on the date of this answer, but I'll keep that part for didactic and historical purposes.

On the Add View screen, Template field, choose your template from ViewModel . Place the Model Class as the Model to use as the base and click Ok.

If all goes well, the Scaffold of your ViewModel should occur smoothly.

The correct step, without chuncho

The neat way to do the same thing is using the MvcScaffolding.VS2015 package .

For Views , use the description for this answer .

For Controllers , the principle is the same, but you will copy the Scaffold script that is in packages\MvcScaffolding.VS2015.<versão>\tools\Controller\MvcScaffolding.Controller.ps1 and make the appropriate modifications.

If you need help with the changes, just talk.

    
05.10.2015 / 17:52