I have a need to map both a related entity and it's id. For example:
public class Person : Entity {
public virtual string FullName { get; set; } public virtual int FavoriteFoodId { get; set; } public FavoriteFood FavoriteFood { get; protected set; }
}
The reason is that I am using an Html.DropDownList and the data value for each option is the favorite food id. On post, the receiving action binds a new Person. The person class must have a property setup to receive that data, or I have nothing which to determine what food they selected. I can't name the drop down 'FavoriteFood.Id' either because the binder looks for a field with that exact name, and doesn't know to try using object.field. I can't apply a prefix to a single field either, they affect the whole entity on bind. So I am kind of left scratching my head on this one.
In testing, it seems you can have one or the other (field or entity) but not both. Adding both generates index errors upon query. I really don't want to resort to yet another third party component set just get this to work. Nor do I need some convoluted workaround.
If there's a way to do this, please let me know. Thanks!
|