c# - Select specific item from multi-object ViewModel -
i have viewmodel wraps 2 lists of different objects: list<review> , list<daycommentary> reviewviewmodel. list<daycommentary> collection of either 0, 1 or max 2 elements, different daycommentary.commentaryfor (string parameter) values.
in view, need display textarea 1 of elements in list<daycommentary> in 1 section of page , textarea element in section of same page.
i tried achieve code below throws error during runtime:
@html.textareafor(model => model.daycommentary.select(c => c.commentaryfor == "day"), new {@class = "form-control commentary", @style = "max-width: none"}) error:
templates can used field access, property access, single-dimension array index, or single-parameter custom indexer expressions. i assume it's not happy linq select statement.
what best way achieve i'm trying do, while still binding model posting controller during formmethod.post?
model.daycommentary.select(c => c.commentaryfor == "day") this doesn't make sense return collection of bools.
perhaps meant
model.daycommentary.first(c => c.commentaryfor == "day").commentaryfor if want text area each element in daycommentary collection, use foreach loop on collection. let me know if you're not sure how i'll happily add example code answer.
Comments
Post a Comment