Guest User

Untitled

a guest
Jun 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. IdName[] Thing = new[] {
  2. new IdName { Id = 0, Name = "No Selection" },
  3. new IdName { Id = 1, Name = "Thing A9" },
  4. new IdName { Id = 2, Name = "Thing C12" },
  5. new IdName { Id = 3, Name = "Thing F4" }
  6. };
  7.  
  8. MyDropDownList = new SelectList(Things, "Id", "Name",0);
  9.  
  10. <%= Html.DropDownList("MyDropDownList")%>
  11.  
  12. public ActionResult StoreValueFromDropDown(string MyDropDownList) {
  13. var id = Things.Single(thing => thing.Name == MyDropDownList).Id;
  14. // here goes the code to sotre the id
  15. }
  16.  
  17. <input type="hidden" id="ThingId" />
  18.  
  19. $('#MyDropDownList').change(function(e){
  20. $('#ThingId').value($('#MyDropDownList option:selected').attr('value'));
  21. });
  22.  
  23. public ActionResult StoreValueFromDropDown(int ThingId) {
  24.  
  25. // here goes the code to sotre the id
  26. }
Add Comment
Please, Sign In to add comment