我正在尝试根据控制器中的 if/else 条件为我的 viewbag 创建动态属性。viewbag 显示的内容取决于我在控制器中的逻辑。在我看来,我尝试用剃刀语法调用我的视图包,但页面上没有任何内容。
[HttpPost]
public ActionResult EditUser(vw_UserManager_Model edituser)
{
UserManager.Models.vw_UserManager_Model model = edituser;
int outcome = 0;
outcome = UserManager.DAL.EditUser(model);
if (outcome == 1)
{
ViewBag.Message = "Successfully edited user" + model.UserName;
ViewBag.Description = "Look below for full details.";
//ViewData["Message"] = "Successfully edited user" + model.UserName;
return RedirectToAction("showSuccess", model);
}
else
{
ViewBag.Message = "Failure";
return RedirectToAction("showFailure", model);
}
}
#region successErrorHandling
public ActionResult showError(List<string> ErrorMessage)
{
ViewBag.ErrorMessage = ErrorMessage[0];
return View("ErrorMessageView");
}
public ActionResult showSuccess(vw_UserManager_Model model)
{
return View("SuccessMessageeView", model);
}
我为 viewbag、message 和 description 设置了两个属性。如果成功或失败,我会进行重定向。
@model UserManager.Models.vw_UserManager_Model
<h2>@ViewBag.Message</h2>
<br />
<h4>@ViewBag.Description</h4>
<h2>
SuccessMessageeView</h2>
<br />
User Created:
@using (Html.BeginForm())
{
<ul>
<li> <b>@Html.Label("Username: ")</b>@Model.UserName</li>
<li> <b>@Html.Label("Salutation: ")</b>@Model.salutation</li>
<li> <b>@Html.Label("Firstname: ")</b>@Model.firstname</li>
<li> <b>@Html.Label("Lastname: ")</b>@Model.lastname</li>
<li> <b>@Html.Label("Email: ")</b>@Model.email</li>
<li> <b>@Html.Label("Group name: ")</b>@Model.group_name</li>
<li> <b>@Html.Label("Is active: ")</b>@Model.isactive</li>
</ul>
}
在我看来,然后我调用我的 viewbag,但它不会渲染。我做错了吗?