MVC 3中的下拉列表 [英] Dropdownlist in MVC 3

查看:89
本文介绍了MVC 3中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是MVC 3的新手.我想做下面的事情.

我创建了两个模型类Item1和Item2.

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; }
}

和一个dataContext类

And One dataContext class

public class ItemDBContext:DbContext
    {
        public DbSet<Item1> Items1 { get; set; }
        public DbSet<Item2> Items2 { get; set; }
    }




我正在使用以下代码填充下拉列表中的Controller Index()方法中的否




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();
}

现在,在视图中,我正在使用这两个ViewBag来填充两个dropdon列表.

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 />


}

这两个下拉列表均已正确填充.

现在我想做如下.我不知道该怎么做.

从第一个"下拉列表中选择任何值后,单击>>"按钮,则应将所选项目从第一个下拉列表中删除,然后将其添加到第二个下拉列表中.同样,这也应该在数据库中完成.

请任何人告诉我我该怎么写

[HttpPost]版本的Index()方法.


请帮助我解决这个问题.我真的需要这个东西.

提前致谢.
Suman Zalodiya.


}

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.

推荐答案

您无需发回邮件即可.只需使用 jquery [ ^ ]在列表之间移动项目.
You don''t need to post back to do this. Just use jquery[^]to move items between the lists.


这篇关于MVC 3中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆