asp.net mvc - C# MVC DropDownListFor List of Strings -


i working list of string items in mvc needs selected drop down list. drop down list binding fine, , value's setting fine, though current item being iterated matches item in drop down list isn't being pre-selected it's value, can point me in right direction?

    @for (var = 0; < model.stringlist.count; i++)     {         if (bl.helpers.stringhelpers.validate(model.displaystringsegments[i]))         {             <div id="editor-field">                 @html.dropdownlistfor(m => m.stringlist[i], model.posteroptions, string.empty, new { })             </div>         }         else         {             <div id="editor-label">@model.stringlist[i]</div>             @html.hiddenfor(model => model.stringlist[i])         }     } 

so case, options list of strings holding 1 value, "test" -> set both text , value;

       posteroptions.add(new selectlistitem() { text = "test", value = "test" }); 

can tell me why current stringlist[i] isn't being pre selected, though has value of "test" ?

for comes across this;

i had "hack" solution, did by:

changing viewmodel's (model.options)

list<selectlistitem> list<string> 

changing drop down list selection following, forcing selected value;

            <div id="editor-field">                 @{                     string currentstring = model.stringlist.elementat(i).tostring();                  }                  @html.dropdownlistfor(m => m.stringlist[i], new selectlist(model.options, currentstring), string.empty, new {})             </div> 

perhaps there better way, works!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -