我有一个 ASP.NET MVC 3 项目,其中包含模型绑定(bind)到 View 模型的 POST 操作
[HttpPost]
public virtual ActionResult Reply(ReplyViewModel viewModel)
{
// ...
}
我有一个 ActionFilter
,我想在 OnActionExecuted
中查看该 View 模型,但 ViewData.Model
为空。我是否误解了 ViewData.Model
是什么?
public class CopyViewModelToTempDataAttribute : System.Web.Mvc.ActionFilterAttribute
{
public override void OnActionExecuted(System.Web.Mvc.ActionExecutedContext filterContext)
{
// filterContext.Controller.ViewData.Model is null
}
}
最佳答案
这可能是这个问题的解决方案 1. 我假设您分配了 Model in Action
现在来过滤
public override void OnActionExecuted(System.Web.Mvc.ActionExecutedContext filterContext)
{
if(filterContext.HttpContext.Request.HttpMethod == "POST")
{
// Get your model here.
}
}
关于asp.net-mvc-3 - filterContext.Controller.ViewData.Model 在 ActionFilter.OnActionExecuted 中为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8549814/