views:

554

answers:

1

So far we can use Html.EditorFor() to dynamically render the appropriate template for a datatype - e.g. string, int, or a custom type, say 'Address'.

Now I want to use EditorFor() to render a 'Parent' field. I want a drop-down containing every row, and the user picks a parent from this drop-down.

The 'Parent' template has access to the 'ParentID', but what about the names and ID's of rows, to populate the list-box with?

Where should these come from?

I could put data-access logic in the template, but that would be violating the separation of concerns.

I could create an HtmlHelper that renders the list, but wouldn't this also break separation of concerns, since HtmlHelpers should only do UI stuff, not data access?

Any ideas?

+1  A: 

You could try a MVVM approach, maybe? Your ViewModel would contain all the data you need to render the dropdown, as well as an "edit" model to store the user's input upon a POST, which would just be an ID number in this case, I guess.

mgroves