Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0 MVC3 Razor Entities , +
Hi All,
I am new to the MVC 3. I want to do like below.
I have created two Model Class Item1 and Item2.
class Item1
     public int Item1ID {get; set; }
     publid string ItemName {get; set; }
class Item2
     public int Item2ID { get; set; }
     public string ItemName {get; set; }
And One dataContext class
public class ItemDBContext:DbContext
        public DbSet<Item1> Items1 { get; set; }
        public DbSet<Item2> Items2 { get; set; }

No in controller Index() methos i am populating the dropdown list using below code
public ItemDBContext db=new ItemDBContext();
public ActionResult Index()
       ViewBag.item1List=new SelectList (db.Item1s, "Item1ID","ItemName","Please select any one");
       ViewBag.item2List=new SelectList (db.Item2s, "Item2ID","ItemName","Please select any one");
       return View();
Now in view I am using these two ViewBag to populate two dropdon list.
@using (Html.BeginForm())
       @Html.DropdownList("item1List",string.Empty); <br />
       <input type="submit" name="onetotwo" text=">>" /> <br />
       <input type="submit" name="twotoone" text="<<" /> <br />
@Html.DropdownList("item1List",string.Empty); <br />
Both the dropdownlist are populated properly.
Now i want to do like below. I don't to how to do this.
After selecting any value from First dropdown list and click on ">>" button then that selected item should removed from first dropdownlist and it should be added to second dropdownlist. Same this should be done in database too.
Please can anyonce tell me how can i write the
[HttpPost] version of the Index() method.

Please help me to resolve this isse. Really i need this thing.
Thanks and Regards in Advance.
Suman Zalodiya.
Posted 22-Aug-12 9:03am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You don't need to post back to do this. Just use jquery[^]to move items between the lists.
suman161288 at 22-Aug-12 14:16pm
Hi Christian
Thanks for the prompt reply.
I am not able to open this link in the office premises. Please can you provide me the solution.
Christian Graus at 22-Aug-12 14:22pm
It's just an article on how to use jquery. $('#ddlMyCombo').append($('< option > </option>').val(1).html(option1Text)); is how you append an item to a list. $("#ddlMyCombo option[value='option1Text']").remove(); is how you remove them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 645
1 Maciej Los 225
2 Richard Deeming 160
3 Suvendu Shekhar Giri 159
4 Abhinav S 151
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,135
2 Peter Leow 5,042
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100