Using EditorFor <> to display a dropdown

So far, we could use Html.EditorFor () to dynamically display the corresponding template for a data type โ€” for example, string, int, or a custom type, for example โ€œAddressโ€.

Now I want to use EditorFor () to display the Parent field. I want a dropdown list containing each row, and the user selects a parent from this dropdown list.

The Parent template has access to the ParentID, but what about the names and line identifiers to populate the list with?

Where did they come from?

I can put the data access logic in the template, but this will break the separation of problems.

I could create an HtmlHelper that displays a list, but wouldn't that break the separation of problems, since HtmlHelpers should only do user interface stuff, not data access?

Any ideas?

+4
source share
1 answer

Could you try the MVVM approach maybe? Your ViewModel will contain all the data needed to render the pop-up menu, as well as an โ€œeditโ€ model for storing user input during POST, which I suppose will simply be an identification number in this case.

+2
source

All Articles