I have not been using "model binding" in my MVC application -- that is, I haven't tried the thing of "mapping" form inputs to one or more classes in the Action parameter list, in the manner that is described in many places. Instead, I just send over parameters for each individual form field, or use FormCollection.
I was thinking I might like to try this, but I am confused about the basic premise. It seems the idea is that you use the same model for your "binding" (going from View to Controller) that you use for your ViewModel (going from Controller to View). (I am using strongly-typed views with a separate ViewModel for each View.)
Yet, I find that the needs of my View are quite different from the needs of my Action -- the View, for example, may need several SelectLists from which the user can choose. The Action, however, only needs to know which items the user has chosen, not all the options in each list.
It is really customary to use the same class going in both directions?
For example, here is one of my ViewModel classes:
public class IntervieweeSelectLists
{
public SelectList intervieweesList { get; set; }
public ClientSelectLists districtFilterLists { get; set; }
public SchoolDisplayListInfo schoolListDisplay { get; set; }
public long selectedIntervieweeID { get; set; }
public string selectedIntervieweeName { get; set; }
public string selectedSiteID { get; set; }
public bool needsInterviewList { get; set; }
public bool needsClientSelectLists { get; set; }
}
(Plus there are some methods, etc.)
This class is needed by the View, but not all of it is needed by the Action -- i.e., intervieweesList, districtFilterLists, needsInterviewList, etc.
I guess my question is: if I were to write a custom model binder to bind this class, would I have to recreate the whole class in the model binder, including the SelectLists, the contents of which come from the database, when all I really need is the things the user has selected? Or would I set all the values from an existing instance of this class, sent in to the model binder from the View?
Sorry if this is incoherent ... something is missing from my understanding here. Help! :)