我创建我的分支,在这里我选择下拉列表来选择我的公司,在下拉列表中绑定公司ID和公司名称。当我创建编辑功能时,我填写了所有必填字段,当我单击编辑按钮时,我发现我的com_id双,例如:04是我的真实ID,我得到“ 0404”,现在我该如何解决?
这是我的控制器,
public ActionResult Edit(string id)
{
Branch model = new Branch();
var br = erkDB.m_br.FirstOrDefault(x => x.br_id == id);
model.br_id = id;
model.br_nam = br.br_nam;
model.br_add = br.br_add;
model.br_eml = br.br_eml;
model.br_fax = br.br_fax;
model.br_mob = br.br_mob;
model.br_typ = br.br_typ;
model.com_id = br.com_id;
var com = erkDB.m_com.ToList();
foreach (var item in com)
{
Company company = new Company();
company.com_nam = item.com_nam;
company.com_id = item.com_id;
model.comModel.Add(company);
}
return View("Create", model);
}
[HttpPost]
public ActionResult Edit(Branch model)
{
if (ModelState.IsValid)
{
var br = erkDB.m_br.FirstOrDefault(x => x.br_id == model.br_id);
var temp = Request.Form["com_id"].ToString();
string strNew = temp.Replace(",","");
//br.br_id = br;
br.br_nam = model.br_nam;
br.br_pho = model.br_pho;
br.com_id = strNew;
br.br_web = model.br_web;
br.br_mob = model.br_mob;
br.br_eml = model.br_eml;
br.br_fax = model.br_fax;
br.br_typ = model.br_typ;
// mvcdb.m_com.Add(company);
erkDB.SaveChanges();
return RedirectToAction("Index");
}
return View("Create", model);
}