Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IdName[] Thing = new[] {
- new IdName { Id = 0, Name = "No Selection" },
- new IdName { Id = 1, Name = "Thing A9" },
- new IdName { Id = 2, Name = "Thing C12" },
- new IdName { Id = 3, Name = "Thing F4" }
- };
- MyDropDownList = new SelectList(Things, "Id", "Name",0);
- <%= Html.DropDownList("MyDropDownList")%>
- public ActionResult StoreValueFromDropDown(string MyDropDownList) {
- var id = Things.Single(thing => thing.Name == MyDropDownList).Id;
- // here goes the code to sotre the id
- }
- <input type="hidden" id="ThingId" />
- $('#MyDropDownList').change(function(e){
- $('#ThingId').value($('#MyDropDownList option:selected').attr('value'));
- });
- public ActionResult StoreValueFromDropDown(int ThingId) {
- // here goes the code to sotre the id
- }
Add Comment
Please, Sign In to add comment