我有这段代码
|Year | customer_id |
|2010 | 1 |
|2010 | 2 |
|2011 | 2 |
|2011 | 3 |
|2012 | 1 |
和这个HTML
[HttpGet]
public ActionResult DeleteKamion(int id)
{
using (TruckCompanyEntities1 databaseKamion2 = new TruckCompanyEntities1())
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Kamioni KamionDelete = databaseKamion2.Kamionis.Find(id);
if (KamionDelete == null)
{
return HttpNotFound();
}
return View();
}
}
[HttpPost, ActionName("DeleteKamion")]
public ActionResult DeleteKamionConfirmed(int id)
{
using (TruckCompanyEntities1 databaseKamion10 = new TruckCompanyEntities1())
{
Kamioni SoferDeleteConfirmed = databaseKamion10.Kamionis.Find(id);
databaseKamion10.Kamionis.Remove(SoferDeleteConfirmed);
databaseKamion10.SaveChanges();
return RedirectToAction("DisplayUserDetailsKamion");
}
}
问题是,当我按下DELETE视图时没有显示模型的值,但是当我按下删除按钮时,我也想显示信息,请帮助谢谢。
答案 0 :(得分:2)
这是因为你正在返回视图emtpy ..视图正在期待一个模型。提取数据但不返回。
[HttpGet]
public ActionResult DeleteKamion(int id)
{
using (TruckCompanyEntities1 databaseKamion2 = new TruckCompanyEntities1())
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Kamioni KamionDelete = databaseKamion2.Kamionis.Find(id);
if (KamionDelete == null)
{
return HttpNotFound();
}
return View(KamionDelete);
}
}