C# 在ViewEngine ASP.NET MVC 3中获取属性值
我正在编写自己的视图引擎C# 在ViewEngine ASP.NET MVC 3中获取属性值,c#,asp.net-mvc,attributes,controller,C#,Asp.net Mvc,Attributes,Controller,我正在编写自己的视图引擎 public class MyViewEngine : RazorViewEngine { public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { // Here, how do I get attributes defined o
public class MyViewEngine : RazorViewEngine
{
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
// Here, how do I get attributes defined on top of the Action ?
}
}
上面的问题是如何在控制器上定义属性。但我需要在动作中定义属性
public class MyViewEngine : RazorViewEngine
{
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
var controllerType = controllerContext.Controller.GetType();
var actionDescriptor =
new ReflectedControllerDescriptor(controllerType)
.FindAction(
controllerContext,
controllerContext.RouteData.GetRequiredString("action")
);
var attributes = actionDescriptor.GetCustomAttributes(typeof(...), false);
// TODO: do something with the attributes that you retrieved
// from the current action
}
}