【发布时间】:2014-04-09 05:49:30
【问题描述】:
我在 MVC3 应用程序中有一个自定义操作过滤器
public class CustomActionFilter:ActionFilterAttribute
{
public Func<IDictionary<string, object>, bool> AdditionalCheck { get; set; }
public CustomActionFilter()
{
}
public CustomActionFilter(Type declaringType, string methodName)
{
MethodInfo method = declaringType.GetMethod(methodName);
AdditionalCheck = (Func<IDictionary<string, object>, bool>)Delegate.CreateDelegate(typeof(Func<IDictionary<string, object>, bool>), method);
}
}
我想将此用作可以在操作上提供的附加检查。问题是它会抛出“Error binding to target method”。我创建了一个控制台应用程序,它能够创建委托。这是网络项目中的问题吗?
我也试过了:
AdditionalCheck = (Func<IDictionary<string, object>, bool>)Func<IDictionary<string, object>, bool>.CreateDelegate(typeof(Func<IDictionary<string, object>, bool>), method);
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 c#-4.0 delegates