I have a view and a model (say Car). One field is editable in the form (the other info is only shown). When the view form get posted, I need all the info, not only the editable property. But all the other properties are null.
I used to create hidden fields to post the data, but when you have more hidden field than non-hidden ones, it’s makes really dirty code.
Is there a way of posting all properties of a model without using hidden fields?
You should use a ViewModel with the editable fields only.
In the view just place the id for the model in database as a hidden field.
In your controller, get the model from database. Then do some check if you indeed can modify this item (someone could change the id in hidden field using Firebug for instance).
Then, just update the database model with the fields in your ViewModel… and save the model to database again.
If you use your CAR model in the view, someone could change more fields than you permitted… if you use CarViewModel, it is impossible as the model binder will just bind the properties of the viewmodel.