ASP.NET MVC - model binding for different views at runtime

My last project involved actions that return different views at runtime (to put it simply, the application has several different clients as users, and they want their own custom data entry form forms - all of these forms have the same graphical graph object , but their display of model data is radically different from each other) ...

For example, a Case object has several people associated with it. Some forms only display individual Faces fields, other forms support multiple Faces, and others do not contain character information. Also, forms have different levels of fields - many forms lack many of the fields that others have.

Because of this completely different behavior, I believe that I will need a different binding device for each type of design.

Can StackOverflow recommend a course of action in this case, or an alternative solution that simplifies the code.

+3


source to share


1 answer


If all of your view models are based on a common abstract base view model, you could force your POST action to use that common view model as a parameter, and then write your own nexus that will instantiate and bind the correct instance, assuming each view sends an additional parameter containing a specific type.



Here's an example of how you can do this.

+2


source







All Articles