0

I'm quite new as an asp.net mvc developer and my current question is about the EditorForModel HtmlHelper that I'm indulged to use to save on repetitive markup within my application.

But I'm also hesitant because it seems a bit unflexible when it comes to the layout of the form.

One of my cases is a rather large form with surely 30+ fields for the user to enter. Naturally this kind of form is divided into different sections and the sections are even distributed between to columns. To use EditorForModel I assume I would have to create subclasses that are members of the ViewModel class and then create partial views for each member where I can call EditorForModel to render that part of the overall model.

In essence I think my question is this: Should the ViewModel classes represent the actual user interface view that strictly or should the view it self (.cshtml) be responsible for the final layout of the form?

Also, if I have certain fields that break the repetitive markup of [wrapper with label and input field], for example the combination of a postal code and the city where the fields should line up beside each other instead of after each other, am I then supposed to wrap those properties (probably the entire adress) within its own class and create a specific EditorTemplate for that?

All of this seems a bit overkill to me, but in the end I can also see that it might be a good thing to do. Any input would be very welcome before I embarge on making these refactorings for already existing forms...

Dan Pettersson
  • 713
  • 5
  • 17
  • Your viewmodel classes do NOT have to inherit from any particular class. – David Tansey Apr 06 '14 at 16:11
  • Here's a small debate about the wisdom of using EditorForModel templating -- http://stackoverflow.com/questions/6537220/why-not-use-html-editorformodel . Hope that helps. – David Tansey Apr 06 '14 at 16:18

0 Answers0