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?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- MVC-Routing,Why i can not ignore defaults,The matc
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
I use version control - GIT to do it quickly and safely. I use Git Extensions (http://code.google.com/p/gitextensions/) user interface for git.
Have your code commited before re-scaffolding. Then re-scaffold the views, and go to staging (the button Commit in Git Extensions). It shows all changes that re-scaffold made and colors the new and deleted code lines. From there you can stage only the selected new lines, that changed in controller. After staging selected lines, reset the unstaged other changes.
There you have it! Your already modified code with new scaffolded parts. Do any edits and testing necessary and commit.
Yes, you can re-scaffold by scaffolding the same model again, using the same model class and controller names as before. Your existing controller and views will be replaced.
Details: Right click on your project or controller folder,
Add ... New Scaffolded Item,
MVC 5 Controller with views using Entity Framework,
Add
Choose your model and data class,
And ensure your controller name is the same as the one to replace.
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) Save the existing project/solution to version control just as good practice.
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) 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) 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.
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.