c# - MVC5 Custom Binding: List of Strings to List of Complex Type -


in asp.net mvc 5 application i'm writing, 1 material can have many names (materialnames). have build web interface add, edit, , delete names material on edit , create pages of material. achieve have multiple text-inputs on pages named material.materialnames. can added , deleted client-side javascript change number of names. not need indices in names of inputs because data user should see , edit flat list of strings.

these relevant parts of models:

public class materialvm {     public material material { get; set; }     // ... } public class material {     public int id { get; set; }     public list<materialname> materialnames { get; set; }     // ... } public class materialname {     public int id { get; set; }     public string name { get; set; }     public int materialid { get; set; } } 

now work great if material.materialnames of type list<string>. in case model binder can not create materialnames multiple string values passed form data. believe default approach fix be

writing custom model binder

is idea in answer (= override bindproperty , change behaviour 1 propertytype)? combine globally registering binder type materialvm.

do miss simpler option?

isn't possible offer default binder method cast/convert/serialize/... simple type complex type? approach how write custom model binder correct? there other options i'm missing make more intuitive?

the view model should catering view should have

list<string> materialnames

the mvc binding bind view model.

then in controller or whatever layer handle mapping can map materialvm material.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -