只是想知道是否可以更新连接到 ASP.NET MVC 中的模型的 View 。
我首先使用实体框架数据库,它为解决方案创建了一个 .edmx 对象模型。
我基于该模型创建了一个新的脚手架模型,它创建了:
如果我在模型中添加一个属性,如何使用新属性自动更新这些 View 以在 UI 中表示更新的模型?
最佳答案
如 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.
请注意,这显然也会覆盖您的 Controller 。确保有备份并使用源代码控制。
关于asp.net-mvc - 修改模型时更新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21089378/