1

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!

Derek
  • 952
  • 3
  • 13
  • 34
  • Have you tried editing the scaffolding and then running the website? – ywm May 08 '13 at 16:10
  • @ywm - by "scaffolding", do you mean the generated results of the scaffolding? Yes, I have edited the View that the scaffolding built for me, and it works just fine. I'm not clear on whether that's a good idea to do, though. – Derek May 08 '13 at 16:13

2 Answers2

1

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.

Kenneth
  • 28,294
  • 6
  • 61
  • 84
  • Both you and Thiago gave satisfactory (and similar) answers, but you posted first and also went into a little more detail about my core concern, so you get the accepted answer. Thanks! – Derek May 09 '13 at 12:57
1

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

Community
  • 1
  • 1
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • 1
    I agree that using a ViewModel can definitely be a good thing, since it gives even more separation between the View and your entity class. But should you go that route, you're back to handling some of the behind-the-scenes plumbing to link up the ViewModel with your entity class and related data access. A library such as AutoMapper takes a lot of the pain out of that, but it's still not as simple as letting the MvcScaffolder do nearly all the setup for you. That link is definitely a worthfile read, though. Thanks! – Derek May 08 '13 at 21:11
  • You're right @Derek. But IMO, we're talking about a specific case. Probably he won't do that for each View. – Thiago Custodio May 09 '13 at 12:20