I have successfully mapped my polymorphic structure into the view, however, when I am trying to post user input for a particular derived object, it is not recognizing the derived type in the controller action...
Top-level view for the base type:
@model InformationRequestViewModel
@using (Html.BeginForm("PostInformationRequest", "SomeController", FormMethod.Post))
{
@Html.EditorForModel()
}
View for the derived type:
@model ActiveServiceInformationRequestViewModel
<label>Start date:</label>
@Html.TextBoxFor(x => x.StartDate, new { @class = "u-full-width" })
<label>End date:</label>
@Html.TextBoxFor(x => x.EndDate, new { @class = "u-full-width" })
Post action:
[HttpPost]
public ActionResult PostInformationRequest(InformationRequestViewModel model)
{
if(model is ActiveServiceInformationRequestViewModel)
{
// IT IS NOT DIPPING INTO THIS LOGIC!
// Do something with this particular concrete type...
}
// More derived type checks and relevant logic here...
return RedirectToAction("Index");
}
Base view model:
public class InformationRequestViewModel
{
public int Id {get; set;}
}
Derived view model:
public class ActiveServiceInformationRequestViewModel : InformationRequestViewModel
{
public DateTime StartDate {get; set;}
public DateTime EndDate {get; set;}
}