Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-Scaffold views after changing their model

I'm using Visual Studio 2013 and ASP.Net MVC 5. I've created a bunch of views for my models and then I've changed them. I want to run scaffolding on some models and create some views automatically and then change the automatically-generated views. Is there another way other than re-naming some files or creating another solution and copying stuff?

like image 419
Alireza Noori Avatar asked Dec 12 '13 23:12

Alireza Noori


People also ask

How do you're migration scaffolding?

If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration AddDescriptionCategory' again. Specify the '-Verbose' flag to view the SQL statements being applied to the target database.

How do I re-scaffold database in asp net core?

If you need to re-scaffold the model after database schema changes have been made, you can do so by specifying the -f or --force option e.g.: dotnet ef dbcontext scaffold "Server=. \;Database=AdventureWorksLT2012;Trusted_Connection=True;" Microsoft. EntityFrameworkCore.

What is scaffolding in MVC with example?

Scaffolding is used to define the code-generation framework used in web applications. It uses T4 templates to generate basic controllers and views for the models. It generates instances for the mapped domain model and code for all CRUD operations.


2 Answers

Yes, you can re-scaffold by scaffolding the same model again, using the same model class and controller names as before. Your existing controller and views will be replaced.

Details: Right click on your project or controller folder,

Add ... New Scaffolded Item,

MVC 5 Controller with views using Entity Framework,

Add

Choose your model and data class,

And ensure your controller name is the same as the one to replace.

like image 102
Greg Carrier Avatar answered Oct 02 '22 20:10

Greg Carrier


I use version control - GIT to do it quickly and safely. I use Git Extensions (http://code.google.com/p/gitextensions/) user interface for git.

Have your code commited before re-scaffolding. Then re-scaffold the views, and go to staging (the button Commit in Git Extensions). It shows all changes that re-scaffold made and colors the new and deleted code lines. From there you can stage only the selected new lines, that changed in controller. After staging selected lines, reset the unstaged other changes.

There you have it! Your already modified code with new scaffolded parts. Do any edits and testing necessary and commit.

like image 39
insp Avatar answered Oct 02 '22 21:10

insp