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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -