如果产品已分配给客户,我如何从下拉列表中删除它?
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);
}