我正在开发一个 MVC 4 C# 互联网应用程序。
我有一个 MapLocationCompany 类和一个 MapLocation 类。我在每个 MapLocationCompany 对象之后都有一个 MapLocation 对象列表。
这是我当前的代码:
public class MapLocationCompany
{
public List<MapLocation> MapLocationList { get; set; }
}
在数据库中创建 MapLocationCompany 后,我希望将 MapLocation 对象添加到此 MapLocationCompany。
在将任何 MapLocation 项目添加到 MapLocationCompany 之前,我要求提供 MapLocationList。
这是我的代码:
public IEnumerable<MapLocation> getMapLocationsForCompany(int id)
{
MapLocationCompany mapLocationCompany = getMapLocationCompany(id);
return mapLocationCompany.MapLocationList.ToList();
}
我收到此错误:
System.ArgumentNullException was unhandled by user code
Value cannot be null