Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Html.DropDownList selected value from a list<string>
  2. List<string> x = new List<string> { "string1", "string2", "string3", " string4" };
  3.             ViewBag.Relacion = new SelectList(x);
  4.  
  5.  <div class="editor-label">
  6.             @Html.LabelFor(model => model.Relacion)
  7.         </div>
  8.            <div class="editor-field">
  9.             @Html.DropDownList("Relacion")
  10.             @Html.ValidationMessageFor(model => model.Relacion)
  11.         </div>
  12.        
  13. <script type="text/javascript">
  14.     $(document).ready(function () {
  15.  
  16. $('select[name=Relacion]').val($('#Relaciontext').val());
  17.  
  18. }
  19. </script>
  20.  <div class="editor-field" style="display:none" >
  21.                @Html.TextBox("Relaciontext", ViewData["statecode"])
  22.  
  23.         </div>
  24.    @Html.DropDownList("Relacion")
  25.  
  26. ViewData["statecode"]="string1";
  27.        
  28. @Html.DropDownListFor(model => model.Relacion, (IEnumerable<SelectListItem>)ViewData["Relacion"])