In my ASP.Net MVC3 project, I created a ModelBinder that binds the basemodel. In my view, I am creating an object from a model that inherits my base model. Now I donβt know which model was created through reflection in my ModelBinder when I press the submit button, but how?
ModelBinder:
public class MBTestBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
Models:
[ModelBinder(typeof(MBTestBinder))] public class MBTest { public string Name { get; set; } public MBTest() {} } public class MBAbl : MBTest { public MBAbl() {} public string House { get; set; } }
View:
@model ModelBinderProject.Models.MBTest @using (Html.BeginForm("Index", "Home")) { <fieldset> <div class="editor-field"> @Html.EditorForModel(Model) </div> <p> <input type="submit" value="Create" /> </p> </fieldset>
Controller:
public ActionResult Create(MBTest testItem) {
edit:
with bindingContext.ValueProvider.GetValue("House") I can get the form value, but bindingContext.ModelType thinks my MBTest model
source share