【发布时间】:2016-12-18 03:52:21
【问题描述】:
我有一个通用动作过滤器,我想在OnActionExecuting 方法中获取当前模型。我目前的实现如下:
public class CommandFilter<T> : IActionFilter where T : class, new()
{
public void OnActionExecuting(ActionExecutingContext actionContext)
{
var model= (T)actionContext.ActionArguments["model"];
}
}
如果我的所有型号名称都相同,它会很好用。但我想使用不同的模型名称。
如何解决这个问题?
编辑
public class HomeController : Controller
{
[ServiceFilter(typeof(CommandActionFilter<CreateInput>))]
public IActionResult Create([FromBody]CreateInput model)
{
return new OkResult();
}
}
【问题讨论】:
-
@user2184057 这是视图模型,不是请求模型
标签: c# asp.net-core asp.net-core-mvc