Search code examples
asp.net-mvcvisual-studio-2013scaffolding

Updating scaffolded controllers and views with model changes


For the basic functionality of my project I've been defining Entity Framework models and then using the scaffolding feature of Visual Studio to implement CRUD functionality (Right Click -> Add -> New Scaffolded Item...).

If I need to make a change to the model after I've done this, how do I make the scaffolded controllers and views update to the latest model changes? For example, I'm seeing the need now to add a new attribute to my model and change the data type of an existing one, but the controllers and views likely won't work after the change.

I could always just re-scaffold, but I've made some changes to the controller and views already which I don't want to lose. Is my only solution to make the changes myself?


Solution

  • Rename the files having your changes, scaffold again, and replace the newly-scaffolded files with your originals.

    Naturally, you'll have to reconcile any domain changes that were made to the files containing your changes.