Click here to Skip to main content
Rate this: bad
good
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; }
}
And
 
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
good
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.
  Permalink  
Comments
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 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2014
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