我的控制器的Index()方法引用一个类型(ExternalSourceProvider),它在控制器的开头指定为成员:
ExternalSourceProvider externalSource; // GET: Index public ActionResult Index() { externalSource = new ExternalSourceProvider();
我收到ExternalSourceProvider()的错误; 在最后一行,说它由于它的保护级别而无法访问.这是ExternalSourceProvider的定义:
public class ExternalSourceProvider { ExternalSourceProvider() { } public string ExternalSiteAbsoluteURI { get; set; }
我错过了什么?
您必须将默认构造函数标记为public.
public class ExternalSourceProvider { public ExternalSourceProvider() { } public string ExternalSiteAbsoluteURI { get; set; } }
就像现在一样,它无法在这里访问
externalSource = new ExternalSourceProvider();