My project has several models, some with 1:many relationships with other models. A user has a profile page, this is split up into several partial views - each grouping/representing specific attributes of the given model.
If for example, I want to display 5 of the 10 properties of a given model in a partial view, and want to persist the properties that aren't shown to the user I'm using Html.HiddenFor
like so
@Html.HiddenFor(x => x.IsInGroup)
This works for single entry properties as above. Of the 5 hidden member attributes, one of these may be a list. I understand that a list cannot be persisted using HiddenFor
. I've come across the Mvc Futures package and the Html.Serialize
helper extension, but I'm not totally sure how to use it and havn't been able to find much good information on it.
- Once a model is passed to a view everything associated with it (properties, collections) is available for us to access e.g.
Model.Username
. If for example we don't useHiddenFor
withUsername
, does that mean it will be reset to a default value, or null? Is this the same for collections? - Is using
HiddenFor
the only/best way to persist a model's properties that are not shown to the user? - Is using
Html.Serialize
the only way persist a model's collection that is not shown to the user? Other options? - Could someone provide/link to a simple example of how to persist a collection in a situation similar to what I've described?
- If I was to use
Html.Serialize
, does the whole model need to be serialised or can I just serialise the collection?
Feedback appreciated.