Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ViewEngine ASP.NET MVC 3中获取属性值_C#_Asp.net Mvc_Attributes_Controller - Fatal编程技术网

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
    }    
}