I've the following class structure.
public BaseClass
{
public int Id { get; set; }
public string Name { get; set; }
}
public ClassOne : BaseClass
{
}
public ClassTwo : BaseClass
{
}
My Controller is like this
public TestController : Controller
{
public ActionResult ClassOne()
{
ClassOne model = new ClassOne();
return View("Create",model);
}
public ActionResult ClassTwo()
{
ClassTwo model = new ClassTwo();
return View("Create",model);
}
My View ("Create") is like this :
@model MvcApplication.Models.BaseClass
@using(Html.BeginForm("Post","Test",FormMethod.Post))
{
@Html.HiddenFor(model => mode.Id)
@Html.TextBoxFor(model => model.Name)
<input type="submit" value="Submit"/>
}
My Post Action is the same for both the models i.e. ClassOne & ClassTwo. On Post how can I know which model is passed in the Post Action whether it is ClassOne or ClassTwo.
[HttpPost]
public ActionResult Post(BaseClass model)
{
/* Code */
}