c# - MVC.NET: define a strongly typed HTML Helper for DropDownList -


i trying find out how define own htmlhelper creating dropdownlist. have following scenarion: using select2 jquery plugin (http://ivaynberg.github.io/select2/) multiple selects search , better interface. model has x id's of tags associated. understand it, these tags can value when html helper @html.dropdownlistfor() used? to

  • write pure html , somehow tell value has stored in list of tag-id's in model

    or

  • make html helper can achieve same effect.

currently have this, see no way of passing selected values model when form gets posted:

<div>         <label>kies je thema's (maximum 2):</label>         <select id="select2select" multiple style="width: 500px">             @foreach (var top in ((list<topic>)viewbag.topids).where(top => top.maintopic == null))             {                 <option value="@top.topicid" class="optiongroup">@top.name</option>                 foreach (var subtopic in top.subtopics)                 {                     <option value="@subtopic.topicid" class="optionchild">@subtopic.name</option>                 }             }         </select>     </div> 

how can selected value in property in list while keeping structure?

extra: can see options have classes, because have main tags , subtags. users can choose either main tags or subtags, can't work <optiongroup> because 'groups' have selectable. give them, depending on class, different format using select2 format.

please try below code rectify problem

 @html.dropdownlistfor(m => top.subtopics, new selectlist(top.subtopics, "topicid", "name")) 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -