1.view显示的select标签内容
                  @Html.ListBox("CategoryId", (MultiSelectList)ViewBag.Categories, new
                  {
                      name = "left",
                      id = "left",
                      size = "8",
                      style = "width:160px;height:180px;",
                      ondblclick = "moveOption(document.getElementById('left'), document.getElementById('right'))"
                  }
                submit提交表单2.Controller
public ActionResult poppuappu2()
        {
            var categories = db.view_retumeyi.Select(c => new {
                CategoryID = c.Id,
                CategoryName = c.COLUMN_NAME
            }).ToList();            ViewBag.Categories = new MultiSelectList(categories, "CategoryID", "CategoryName");            return View();
        }
        [HttpPost]
        public void poppuappu2(FormCollection collection)
        {
            //此处想取得ListBox内显示的内容,ID和列名,并存到数据库            var b = collection["CategoryName"];?
            var a =collection["CategoryID"];?
        }3.表有两个,view_retumeyi视图,有ID和列名,在select标签里全部显示。选中的部分,存到另一张表中。请教,如何取得select标签中选中的值,并存入数据库?

解决方案 »

  1.   

                foreach (var a in CategoryID)
                {
                    var 列名 = db.view_retumeyi.Where(s => s.Id == a).FirstOrDefault().COLUMN_NAME;
                }只能得到ID,得不到name,那么久根据ID,查询name,然后再插入。
    之前一直想的是如何同时获取,ID和name,换种方法了。
    现在在做如何把ID和name存到数据库中。
    本人刚接触ASP,对写法不太了解。
      

  2.   

    【a】对应想要插入表的ID,
    【列名】对应想要插入表的列名。
    正在查如何把这俩插入到表中~~~