asp.net-mvc - 修改模型时更新 View

标签 asp.net-mvc view

只是想知道是否可以更新连接到 ASP.NET MVC 中的模型的 View 。

我首先使用实体​​框架数据库,它为解决方案创建了一个 .edmx 对象模型。

我基于该模型创建了一个新的脚手架模型,它创建了:

  • 创建.cshtml
  • 删除.cshtml
  • 详情.cshtml
  • 编辑.cshtml
  • index.cshtml

  • 如果我在模型中添加一个属性,如何使用新属性自动更新这些 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/

    相关文章:

    asp.net-mvc - Mvc区域路由?

    c# - 如何扩展 Html.Raw 以在显示前清理危险的 HTML 数据

    IOS:切换 View 时内存占用增加(启用ARC)

    ios - 以编程方式在 UIView 上设置 ViewController

    c# - 尝试在不同 DIV 中的同一 View 上显示 CK 编辑器的内容

    java - 在 Activity 切换期间保留 View 中的数据?

    ios - 调整 UIView 的约束。迅速

    javascript - AngularJS: Controller 仅在页面刷新后加载

    c# - ViewData、ViewBag 和 TempData 是否违反了 MVC?

    asp.net - ASP.net MVC Webforms View 引擎的缺点?