views:

192

answers:

2

ScottGu in this post link text shows how one can utilize EditorTemplates for things such as a Country DropDownList. My question is how can one pass a dynamic list of Countries to the EditorTemplate?

A: 

You can pass it in ViewData and feed ViewData from and ActionFilter if the data is required very often (although arguable it is an anti-pattern).

Maxwell Troy Milton King
A: 

Probably the most elegant solution is using a Custom Attribute, you can later access Model metadata using: ViewData.ModelMetadata.

e.g:

[Foreign(Type="DropDown", TableName="Countries")] public int IdCountry { get; set; }

where ForeignAttribute is a class you must declare, and later use it to build your editor template.