How would you implement a model with "dynamic properties" with using mvc/razor? I really am not sure if "dynamic properties" is the correct term.
Scenario: I have a list of items from the DB. Each of these items are then given a set of "properties" from a list of attributes (also from the DB).
In my Item model I think I should have a collection of attributes/properties, correct? Something like
public class Item
{
public int ItemId { get; set; }
public string ItemName{ get; set; }
public virtual ICollection<Attribute> Attributes { get; set; }
}
public class Attribute
{
public int AttributeId { get; set; }
public string AttributeName { get; set; }
}
My goal is to render a view such that if a user selects an item from a dropdownlist, the set of properties associated with the selected item will be shown with the corresponding html input elements (either textbox or dropdownlist).
Example UI when a user selects an item from a dropdownlist (let's say it is a "Camera")
- Camera
- Brand - [textbox]
- Model - [textbox]
- Warranty - [dropdownlist of warranty length]
Example UI when a user selects an item from a dropdownlist (let's say it is a "House")
- House
- Floor Area - [textbox]
- Number of Rooms - [textbox]
- Number of Rooms - [textbox]
Creating/Editing/Deleting a straightforward model like the Attribute defined above is no problem. What's throwing me off is the way to implement the "dynamic properties" described above.
I'm coming from WebForms and still quite new to MVC so take it easy on me ok? :)