Why are displaying and binding reference fields so hard in asp.net mvc 5? -


in rails, common use code 100% of work required creating edit form contains drop down list reference field foriegn key property:

<%= f.input :section, :as => :radio %> 

i'm trying learn asp.net mvc , while there lot love, taking me forever figure out how create drop down list field relates different model.

1) based on everyones advice, i'm going viewmodel pattern, , adding property that

ienumerable<selectlistitem>

2) populate select list item values. (why doesn't default all??)

3) @html.listboxfor(m => m.selectedcategories, model.categorychoices)

4) now, in create/edit method on controller, have read these values , save them?

i feel must missing something. of steps dont bother me except 4. there no automatic binding? (if there is, code doens't work because value empty when try...)

edit: lot of tutorials tried seem reference setting "foreignmodelnameid" field (as in, productid field), model has virtual product field. not sure if affected ability automatically bind or not....

i dont understand purpose of bind="field1,field2,field3" in edit method parameters. can pass foriegn key fields that? need incldue name of key or name of navigation property?


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -