Итак, я пытаюсь написать сайт asp.net практики для сети магазинов велосипедов. Если вы посмотрите на мой индексный указатель для моего объекта хранилища. Как и мой макет db и контроллер, вы можете увидеть, что я намерен отобразить количество просмотров и имена магазинов:Asp.net beginner issues
BikeStoreEntities.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using BikeStore.Models;
namespace BikeStore.Models
{
public class BikeStoreEntities : DbContext
{
public DbSet<Inventory> StoreInventory { get; set; }
public DbSet<Store> Stores { get; set; }
}
}
контроллер
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BikeStore.Models;
namespace BikeStore.Controllers
{
public class StoreController : Controller
{
BikeStoreEntities storeDB = new BikeStoreEntities();
// GET: Store
public ActionResult Index()
{
var stores = storeDB.Stores.ToList();
return View(stores);
}
public ActionResult Details(int id)
{
var bike = new Inventory {SerialNumber=id };
return View(bike);
}
public ActionResult Browse(string name)
{
var store = new Store { Name = name };
return View(store);
}
}
}
Модель
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using BikeStore.Models;
using BikeStore.Models;
namespace BikeStore.Models
{
public class SampleData : DropCreateDatabaseIfModelChanges<BikeStoreEntities>
{
protected override void Seed(BikeStoreEntities context)
{
var stores = new List<Store>
{
new Store { Name = "Rocky Road" , City= " ", Address= " ", Phone= " ", Employees = new List<Employee>(), StoreInventory= new List<Inventory>()},
new Store { Name = "Jazzy Drive" ,City= " ", Address= " ", Phone= " ", Employees = null, StoreInventory= null},
new Store { Name = "Metal Foundry" ,City= " ", Address= " ", Phone= " ", Employees = null, StoreInventory= null}
};
}
}
}
Посмотреть
@model IEnumerable<BikeStore.Models.Store>
@{
ViewBag.Title = "Store";
}
<h3>Browse Stores</h3>
<p>
Select from @Model.Count() Stores:
</p>
<ul>
@foreach (var store in Model)
{
<li>@store.Name</li>
}
</ul>
Однако он печатает "Выбрать из 0 Магазинов", а затем без каких-либо магазинов после него. Кто-нибудь знает, что здесь может быть? Я был бы рад предоставить любые другие файлы проектов, которые, по вашему мнению, актуальны.
вы не показывая свой контроллер. –
@ DanielA.White Там вы идете. –
В вашей базе данных должна быть запись. – Lali