Reputation:
Just wondering if it is possible to update views connected to a model in ASP.NET MVC.
I am using Entity Framework database first which creates a .edmx object model for the solution.
I have created a new scaffolding model based on the model, which created:
If I add a property in the model, how can I update those views automatically with the new property to represent the updated model in the UI?
Upvotes: 16
Views: 19542
Reputation: 151588
As explained in Changing the Database : The Official Microsoft ASP.NET Site:
To update the views you have two options - you can either re-generate the views by once again adding scaffolding for the Student class, or you can manually add the new property to your existing views. In this tutorial, you will add the scaffolding again because you have not made any customized changes to the automatically-generated views. You might consider manually adding the property when you have made changes to the views and do not want to lose those changes.
To ensure the views are re-created, first delete the Student folder under Views. Then, right-click the Controllers folder and add scaffolding for the Student model. Again, name the controller StudentController. When you click Add, you will be asked if you want to replace the existing file named StudentController. Select OK.
The views now contain the [added] MiddleName property.
Note this will apparently also overwrite your controller. Be sure to have a backup and use source control.
Upvotes: 14