0
如果已將產品分配給客戶,我如何從下拉列表中刪除產品?如果已分配,從列表中刪除產品
該ID似乎按正確的順序。並且我做了一些改變,也許我錯過了一些東西
public ActionResult Edit(int id = 0)
{
UserProfile userprofile = db.UserProfiles.Find(id);
if (userprofile == null)
{
return HttpNotFound();
}
var deviceList = db.Devices.ToList();
var userList = db.UserProfiles.ToList();
foreach (var user in userList)
{
deviceList.RemoveAll(x=>x.DeviceID==user.Device_DeviceID);
}
ViewBag.deviceList = new SelectList(db.Devices, "DeviceID", "DeviceIMEI", userprofile.Device_DeviceID);
return View(userprofile);
}
// POST: /User/Edit/5
[HttpPost]
public ActionResult Edit(UserProfile userprofile)
{
if (ModelState.IsValid)
{
db.Entry(userprofile).State = EntityState.Modified;
//db.UserProfiles.Attach(userprofile);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.deviceList= new SelectList(db.Devices, "DeviceID", "DeviceIMEI", userprofile.Device_DeviceID);
return View(userprofile);
}
這是你的意思,它不會從列表中刪除值。 – user2470369
您是否有ID(DeviceID和Device_DevideID正確)?使用斷點來查看這些。 – Shyju
我沒有打電話給deviceList! – user2470369