ASP.NET MVC3 Custom Model Binder Issues -


i have applicant model contains list of tags:

public class applicant {     public virtual ilist<tag> tags { get; protected set; } } 

when form submitted, there input field contains comma-delimited list of tags user has input. have custom model binder convert list collection:

public class taglistmodelbinder : imodelbinder {     public object bindmodel(controllercontext controllercontext, modelbindingcontext bindingcontext)     {         var incomingdata = bindingcontext.valueprovider.getvalue("tags").attemptedvalue;         ilist<tag> tags = incomingdata.split(',').select(data => new tag { tagname = data.trim() }).tolist();         return tags;     } } 

however, when model populated , passed controller action on post, tags property still empty list. idea why isn't populating list correctly?

the problem have protected set accessor in tags property. if change public below things work fine.

public class applicant {     public virtual ilist<tag> tags { get; set; } } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -