Configure Scaffold to generate classes

Asked

Viewed 163 times

2

You can configure Scaffold to generate classes other than the default (Controllers and Views) ?

  • You can generate classes from a ready-made database. Is that it? If not, what classes do you want to generate?

  • No, I want to configure Scaffold to generate classes that I configure as ex.: Clienteviewmodel that will be based on the Client model. I know Scaffold uses Reflection so I thought about the possibility

1 answer

2


Yes.

First you need to generate one template for their Viewmodels. There’s a Nuget package that has several templates as an example.

Once done, modify a template View (save with another name) and put in code everything you would like to have in your Viewmodel. Don’t forget to change the output Extension of:

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

To:

<#@ output extension="cs" #>

To execute his Scaffold, right-click the directory of Viewmodels > Add > New Scaffolded Item... .

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

Note that this step is a drag, precisely because the package I was going to use was bugged on the date of this answer, but I will keep this part for didactic and historical purposes.

On the screen of Add View, field Template, choose your template of Viewmodel. Put the Model Class like the Model to be used as a base and click OK.

If all goes well, the Scaffold of his Viewmodel should occur smoothly.


The correct step, without chuncho

The elegant way to do the same thing is using the Mvcscaffolding.VS2015 package.

To Views, use the description of this answer.

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

If you need help with the modifications, just say the word.

  • I’ll test it. Wouldn’t there be a scaffold that we use to generate the controllers, which in this case already generates the views, to do this? Thanks!

  • I think Controllers are more limited, but it may be too. Please wait for an update of this response in the next few days. David will update his package, then better that.

  • Gypsy, can you help me with this: http://answall.com/questions/90536/mudar-o-padr%C3%A3o-de-nomenclature-das-views-que-s%C3%A3o-geradas-pelo-scaffold

  • I updated here too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.