DefaultHttpControllerSelector不包含带0个参数的构造函数

时间:2014-07-03 19:55:44

标签: c# asp.net-mvc

我的类有以下构造函数,它实现了DefaultHttpControllerSelector

public NamespaceHttpControllerSelector(HttpConfiguration config) // error on this line
{
    _configuration = config;
    _duplicates = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
    _controllers = new Lazy<Dictionary<string, HttpControllerDescriptor>>(InitializeControllerDictionary);
}

VS给我一个错误,上面写着DefaultHttpControllerSelector does not contain a constructor that takes 0 arguments

但是,当我转到DefaultHttpControllerSelector的定义时,它显示了这一点:

public DefaultHttpControllerSelector(HttpConfiguration configuration);

我做错了什么?我将正确的参数传递给构造函数,对吗?

注意:这是在MVC 5中。

1 个答案:

答案 0 :(得分:4)

您需要调用基类构造函数:

public NamespaceHttpControllerSelector(HttpConfiguration config)
    : base(config)
{
}