Guest User

Untitled

a guest
May 4th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  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"])
Advertisement
Add Comment
Please, Sign In to add comment