I scaffolded a new MVC controller, along with a corresponding view and repository for an IEnumerable collection of a POCO class. In the resulting view is a table that will list every entry in the collection of that class. However, the table also contains a column for every property in that class, and I only want to display a subset of them in this view. Is it a bad idea if I now manually edit the view to remove what I don't want to display in the generated HTML?

I'm not clear on whether the scaffolding features that are part of ASP.NET MVC (version 3 and later) are designed to generate the basic functionality for your web application, giving you the freedom to do what you want with the results afterwards, or if it's considered a best practice to leave the generated results alone and find another way to do what I want to accomplish. I know that you can customize your own scaffolding templates, but that seems like a lot of work for such a simple change.

Thanks!

有帮助吗?

解决方案

It's definitely OK to edit the scaffolded view. This is just a feature that's there to quickly build the basics, but that will never suffice.

So you can just edit it all you want. Keep in mind though that if you edit your model, you will have to manipulate your view manually, but that's normal I think.

其他提示

Scaffold will HELP you to generate a View strongly typed to a Model. Of course, if you want, you can update the html in your views. Another good tip: Instead of using your Model, create a ViewModel based on this Model, and put only the properties you need to display in the View.

View this content: https://stackoverflow.com/a/11064362/1384539

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top