【发布时间】:2018-01-25 17:45:40
【问题描述】:
我有 1 个使用 Select2 的下拉列表,
我希望结果有 2 个值,ID 和电子邮件
这是我的控制器
public ActionResult Input(string input, string email)
{
// Populate your ViewModel to store each of those things
var model = new CostVM()
{
error = input,
email = email,
};
ViewData["List"] = new SelectList(db.depts, "id", "jenis");
return View(model);
}
[HttpPost]
public ActionResult Input(CostVM model)
{
FormCollection a = new FormCollection(Request.Unvalidated().Form);
var mail = db.depts.ToList();
model.input = string.Join(",", model.selec);
int ttd = 0;
for (ttd = 0; ttd < model.selec.Count(); ttd++)
{
var oke = db.depts.Find(Convert.ToInt32(model.selec[ttd]));
string[] idList = oke.email.Split(new char[] { ',' });
model.email = string.Join(",", idList);
}
return RedirectToAction("Input", "Select", new { input = model.input, email = model.email });
}
我的问题是,如果我添加 2 个或更多选项,则只有一个添加到数据库中
有人可以修复我的代码吗?对不起我的英语不好
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4