我正在尝试从控制器方法传递匿名对象以向用户显示操作反馈消息,例如使用TempData的flash消息,但我收到错误 - ' object'不包含' status'的定义,我该怎么办?
控制器:
[HttpPost]
public ActionResult Create(FriendFormViewModel friendViewModel)
{
TempData["feedback"] = new { status = "success", message = "Success in action" };
return RedirectToAction("Index");
}
查看:
@if (TempData["feedback"] != null)
{
var f = (dynamic)TempData["feedback"];
<div class="alert alert-dismissible action-alert @(f.status)">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<p>succes</p>
</div>}