セッション - TempDataによる一時データTempDataを使う。 サンプルController publc class ItemController
{
[HttpPost]
public ActionResult Delete(int item_id)
{
_itemService.Delete(item_id);
TempData["Alert"] = "削除しました。";
return RedirectToAction("Index", "Item");
}
public ActionResult Index()
{
ViewBag.Alert = TempData["Alert"];
return View();
}
}
View @if (!String.IsNullOrEmpty(ViewBag.Alert)) {
<div class="alert">@ViewBag.Alert</div>
}
参考 |
|