c# - MVC5 model binding -- child objects all null -


when parent class/model posted server , use bindattribute "bind", child objects null.

if don't include binding, works
public actionresult saveedit(int id, person person)

for instance person.address property not null, , it's properties set based upon form submission.

just fyi, address created in view using editorfor, included in request form.

but if use bind, doesn't work..

public actionresult saveedit(int id, [bind(include = "personid, addressid, address.addressid, address.line1, address.city, address.state, address.zip")] person person) 

person.personid , person.addressid set correctly, person.address null.

if use bind , multiple parameters, so...

    public actionresult saveedit(int id, [bind(include = "personid")] person person,         [bind(prefix = "address", include = "addressid, line1, city, state, zip")] address address) 

it halfway works, both object created, neither has related properties there.

is normal behavior, or have done wrong?

you have not shown model, assuming contains properties personid, addressid , address address complex object needs be

public actionresult saveedit(int id, [bind(include = "personid, addressid, address")] person person) 

however, better approach use view model containing properties editing , avoid use of [bind(include = "properties, list")]


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -