-6
我有一个名为“资源库”类实例与数据一些样本的类实例化对象:无法在ASP.NET
public class Repository
{
// create dictionary collection for prices, and define property to get the collection
Dictionary<string, int> prices = new Dictionary<string, int>();
public Dictionary<string, int> Prices { get { return prices; } }
// create List with Reservations, and define property to get the List
List<Reservation> reservations = new List<Reservation>();
public List<Reservation> Reservations { get { return reservations; } }
public Repository()
{
// add prices to the dictionary, prices
prices.Add("Dog", 180);
prices.Add("Cat", 140);
prices.Add("Snake", 120);
prices.Add("Guinea pig", 75);
prices.Add("Canary", 60);
// create customers
Customer c1 = new Customer(1, "Susan", "Peterson", "Borgergade 45", "8000", "Aarhus", "[email protected]", "21212121");
Customer c2 = new Customer(2, "Brian", "Smith", "Algade 108", "8000", "Aarhus", "[email protected]", "45454545");
Reservation r1 = new Reservation(1, "Hamlet", new DateTime(2014, 9, 2), "Dog", new DateTime(2014, 9, 20), new DateTime(2014, 9, 20), c1);
Reservation r2 = new Reservation(2, "Dog", new DateTime(2014, 9, 14), "Samson", new DateTime(2014, 9, 21), new DateTime(2014, 9, 21), c1);
Reservation r3 = new Reservation(3, "Cat", new DateTime(2014, 9, 7), "Darla", new DateTime(2014, 9, 10), new DateTime(2014, 9, 10), c2);
// add Reservations to list of Reservations with instance name reservations
reservations.Add(r1);
reservations.Add(r2);
reservations.Add(r3);
}
}
现在我想在视图中显示的数据,所以我尝试实例它ReservationController
,并将其提供给View:
public ActionResult Index()
{
private Repository repository = new Repository();
return View(repository.Reservations);
}
这将产生一对夫妇就行了错误的,我尝试实例存储库:
无法找到类型或命名空间名称'Repository'(您是否缺少使用指令或程序集引用的 ?)
;预期
无效表达术语“私人”
感谢您使用_actual_构建错误来解决问题。或者它发生的地方。 – HABO 2014-09-26 18:25:09
我只在您的存储库类型上看到价格属性。然而,你引用一个保留属性? – BlakeH 2014-09-26 18:26:24
@SonicTheLichen,当我编辑我的编辑(主要是让VS做格式化)时,我在Repository类中添加了一个结尾括号。虽然这意味着课堂上还有更多未发布的内容,但并未改变_it未被发布的事实。 – gunr2171 2014-09-26 18:31:50