I need a list of different (derived) types of objects that work with ModelBinder by default in Asp.net MVC 2.
I have the following ViewModel:
public class ItemFormModel { [Required(ErrorMessage = "Required Field")] public string Name { get; set; } public string Description { get; set; } [ScaffoldColumn(true)]
And the list contains objects with different derived types, for example
public class TextObject : Core.Object { public string Text { get; set; } } public class BoolObject : Core.Object { public bool Value { get; set; } }
It doesnβt matter if I use the List or ArrayList implementation, everything becomes well-formed in the form, but modelbinder does not allow the properties of the derived type of the object for me when sending back to ActionResult.
What could be a good solution for the Viewmodel structure to get a list of different types of objects? Having an additional list for each type of object (e.g. List, List, etc.), Apparently, is not a good solution for me, since this is a lot of overhead, both when building a model of the view and when displaying it back in domain model.
Thinking of a different approach to linking all properties in the binding of a custom model, how can I use the data annotation approach here (checking the necessary attributes, etc.) without a lot of overhead?
source share