我知道这是最常遇到的错误之一,但我真的很难解决它。我的控制器上有一个属性:
private readonly ISelectListFactory _selectFactory;
以及一个调用来填充 viewbag
private void PopulateLists()
{
var continent = _selectFactory.GetItems();
}
和界面的方法
public interface ISelectListFactory
{
IEnumerable<SelectListItem> GetItems();
}
在控制器构造函数中,我有以下内容:
public LocationController(ISelectListFactory selectFactory)
{
_selectFactory = selectFactory;
}
但我收到此错误 Object reference not set to an instance of an object 并且不知道如何克服它。
问候