I have an asp.net mvc application. I have two model class like this:
public class BaseViewModel
{
...
}
public class DerivedViewModel : BaseViewModel
{
...
}
I have a view and I want to use this view both of these models.
@model BaseViewModel
...
Inside view, I am able to use like this:
@if (Model.GetType() == DerivedViewModel)){
@* Properties of Derived class *@
}
I am using a form inside this view like this:
@using (Html.BeginForm("Home", "Application", FormMethod.Post)) {
...
}
But when I post the form to controller method, I can't cast base class to derived class. How can I separate derived and base class in the controller method? How can I post correctly?