asp.net mvc - Mapping Dynamic Object Inside Complex MVC Model (MVC Model Binder Issue) -


i have dynamic object inside object that inside typed model. model looks this:

public class mymodel     {         public event event{ get; set; }              } 

the event object dynamic search criteria object inside looks this:

public class event {    public string eventname{ get; set; }          public string eventlocation{ get; set;}           public dynamic criteria { get; set; }  } 

below example of base search criteria class. criteria dynamic because different events may have different search criteria.

public class baseeventcriteria     {         [displayname("start date")]                public datetime startdate { get; set; }          [displayname("end date")]                public datetime enddate { get; set; }      } 

the dynmaic object "criteria" renders fine in form inside view when use:

@html.editorfor(o=> o.event.criteria) 

problem when post form controller, "criteria" appears useless "system.object" can't cast appropriate object. understand limitation of mvc default model binder doesn't map dynamic objects. examples saw involving writing custom model binder geared towards model being dynamic, not nested dynamic object inside typed model. can solution either using generics, writing custom model binder, or other solution short of using formcollection object prefer not use?


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -