Click here to Skip to main content
15,885,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am new to the MVC 3. I want to do like below.

I have created two Model Class Item1 and Item2.

C#
class Item1
{
     public int Item1ID {get; set; }
     publid string ItemName {get; set; }
}
And

class Item2
{
     public int Item2ID { get; set; }
     public string ItemName {get; set; }
}
And One dataContext class

XML
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

C#
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.

C#
@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

1 solution

You don't need to post back to do this. Just use jquery[^]to move items between the lists.
 
Share this answer
 
Comments
Suman Zalodiya 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900