I am using ASP.NET MVC and I have several model classes all derived from the parent object. I want to handle all of these models in one controller action since they are nearly identical with the exception of some data fields. I want to save them to a database. How can I achieve such a behavior?
Example:
class ParentModel {...}
class ChildModel1 : ParentModel {...}
class ChildModel2 : ParentModel {...}
class ChildModel3 : ParentModel {...}
class ChildModel4 : ParentModel {...}
public class ModelController : Controller
{
//But with this I want to handle all the child objects as well
//And add them automatically to the database.
public ActionResult Add(ParentModel model)
{
db.ParentModel.Add(model);
}
}