0

(Forgive me for saying the wrong things here because I am completely new to all this terminology. I undoubtedly will use the wrong terms when describing my problem.)

I am learning ASP.NET MVC with C#. I have a model that consists of three columns: EventStart, EventEnd, and Duration. Duration is derived from EventStart and EventEnd so I want to hide it from the Create and Edit views.

I found the DataAnnotation called ScaffoldColumn but that hides the column from all views.

The only thing that comes to mind is to delete this column from the views manually but the problem with that solution, of course, is that I will have to do that every time I change the model and rebuild the MVC scaffold.

What's the best way to do this?

giraffeslacks
  • 77
  • 1
  • 9
  • Why hide it? it's easier just not display it on the view page. – reptildarat Sep 21 '14 at 05:15
  • Best practice to to create a view model for editing. This would include only the properties you want to edit The view model might also include other properties that might be used in the view such as a MaxDate value for use in a jquery DatePicker. Tools such as [automapper](http://automapper.codeplex.com/) make it easy to map to data model to the view model. –  Sep 21 '14 at 05:26
  • @reptildarat Isn't what you described "hiding"? If not, please be more specific. – giraffeslacks Sep 21 '14 at 05:36
  • @StephenMuecke That sounds interesting but complicated. – giraffeslacks Sep 21 '14 at 05:38
  • @giraffeslacks, Its not complicated at all. To get a better understanding, have a look at [these SO answers](http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc) –  Sep 21 '14 at 05:43
  • @giraffeslacks if you want to re-use your current dto's, then just don't display it on the page ( if that you mean by 'hiding' it ). anyway, the convention that recommend by ASP are indeed to create a View Model Dto's as mentioned by StephenMuecke. – reptildarat Sep 21 '14 at 05:50

0 Answers0