我创建了一个 baseviewmodel,我的其他强类型 View 模型继承自该模型。
基础 Controller :
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var baseViewModel = ViewData.Model as BaseViewModel;
if (baseViewModel != null)
{
// set common properties that I want to use in all views
}
}
现在,当我在 if 子句上设置断点时,baseViewModel 似乎始终为 null。
如何将基础 ViewData.Model 设置为 BaseViewModel?
最佳答案
OnActionExecuting现在看模型还为时过早。
Called before the action method is invoked.
您可以在 OnActionExecuted 中看到模型。
关于c# - 创建一个基本 View 模型,但似乎无法在 OnActionExecuting 中 Hook 它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16179391/