c# 4.0 - Passing strongly-typed data from a View to a Controller -
i've got stringly-type view defined using @model mynamespace.customer
form created using html.beginform( "newcustomer", "customerreg", formmethod.post )
helper.
the newcustomer action on customerregcontroller controller looks
[httppost] public viewresult newcustomer( mynamespace.customer objcustomer )
i "filling" model-bound fields on page portion of customer fields.
when submit correct action, objcustomer initial values. though pass strongly-typed data way; doing wrong?
the fact view typed @model mynamespace.customer
doesn't mean model somehow automagically posted action when form submitted. need have input fields each property want retrieve inside form if want property passed post action.
also make sure customer
object poco default (parameterless) constructor each property retrieve has public getters , setters. otherwise default model binder never able deserialize request model. ideal solution problem use view model class design meet requirements of view , stop passing domain models it. view model of course have default constructor , public setters , getters properties retrieve.
Comments
Post a Comment