2

コントローラー アクションからビューに成功メッセージを渡そうとしています。ただし、私が試した、またはグーグルで見つけた解決策は機能していないようです。私が間違っていることを理解しようとして1時間後、ここで質問します。

例では ViewBag を使用していますが、TempDate["MyMessage"] = "Some message"; で試しました。まだ同じ..ビューでは値は常にnullです...

コントローラ

    public ActionResult EditSupplier(Supplier supplier)
    {
        try
        {
            if (ModelState.IsValid)
            {
                this._service.Update(supplier);
                ViewBag.UserMessage = "Supplier updated successfully";

            }
        }
        catch (Exception ex)
        {
            ModelState.AddModelError(String.Empty, ex.Message);
            TempData["UserMessage"] = "Error, supplier couldn't be updated";
            return View("Error");
        }
        return RedirectToAction("Supplier", new { id = supplier.SupplierId });
    }

意見

@if (ViewBag.UserMessage != null)
{
  <p>@ViewBag.UserMessage.ToString()</p>
}
4

1 に答える 1