更改模型后重新折叠视图 [英] Re-Scaffold views after changing their model

查看:112
本文介绍了更改模型后重新折叠视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2013和ASP.Net MVC5.我为模型创建了一堆视图,然后更改了它们.我想在某些模型上运行脚手架,并自动创建一些视图,然后更改自动生成的视图.除了重命名某些文件或创建另一个解决方案并复制内容外,还有其他方法吗?

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?

推荐答案

这是一个老问题的新答案.它与现有的答案有些相似,但我认为有足够的不同和容易之处,才有价值.

This is a new answer to an old question. It's somewhat similar to the existing answers, but I think different enough and easy enough to be of value.

1)按照良好做法将现有项目/解决方案保存到版本控制中.

1) Save the existing project/solution to version control just as good practice.

2)重新搭建脚手架时,请使用不同控制器名称,这将创建一个控制器类,并具有5​​个伴随视图,但不会覆盖任何现有的视图,从而保留所有现有工作.

2) When re-scaffolding, use a different controller name which will create a controller class and it's 5 attendant views, but it won't overwrite anything that exists, preserving all your existing work.

3)从重新安装的控制器中提取适当的方法.当模型更改时,用于创建/编辑的绑定可能会更改,因此请捕获它们.然后删除重新安装的控制器.

3) Extract the appropriate methods from the re-scaffolded controller. Bindings for create/edit will likely change when the model changes, so capture those. Then delete the re-scaffolded controller.

4)保留视图以复制和粘贴任何新的或重新定义的模型属性的相应UI代码.复制所有需要的代码后,只需删除重新构建的视图即可.

4) That leaves the views in place to copy and paste the appropriate UI code for any new or redefined model properties. Once all the code needed has been copied, simply delete the re-scaffolded views.

这是一个很大的问题,因为我们经常不得不更改模型,并且很高兴能自动为我们创建所有基本的UI内容.

It was a great question because we often have to change a model, and it's nice to have all the basic UI stuff automatically created for us.

这篇关于更改模型后重新折叠视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆