My controller action should be usable for a set of models that inherit the abstract class Polis:
public abstract class Polis
{
/// <summary>
/// Fields
/// </summary>
protected Polis()
{
}
public Polis(Object input)
{
// Use input
}
}
My controler action specifies the generic type should inherit this abstract class. But it does not see the constructor of the abstract class that has an argument. So I have to specify that it implements 'new()', instead I would like to use the constructor with an argument.
public virtual ActionResult SavePolis<TModel>(PolisPostModel polisPM) where TModel : Polis, new()
{
if (ModelState.IsValid)
{
// Get the object or save a new object in the database
}
return Json(new
{
success = ModelState.IsValid,
status = this.GetStatus(polisPM),
});
}
All data handling is done inside the inhereting classes, so I need the methods of the inheriting classes to be executed. But when I try to call the controller action giving my specific type as argument it has the error "No overload for method 'SavePolis' takes 0 arguments":
@Html.Hidden("SaveMyPolis", Url.Action(MVC.Controller.SavePolis<MyPolis>())
So what is the correct way to call this? And is it possible that the inherited class is made fully available, so it's methods are called instead of those from the abstract class.