0
public class StoreController : Controller
{
// GET: /Store/
ProductsStoreEntities storeDB = new ProductsStoreEntities();
public ActionResult Index()
{
var items = storeDB.item.ToList();
return PartialView(items);
}
索引視圖MVC 3回到0
model IEnumerable<MvcProductsStore.Models.Item>
@{
ViewBag.Title = "Store";
}
<h3>Browse Products:</h3>
<p>
Select from @Model.Count()
Products:
</p>
<ul>
@foreach (var item in Model)
{
<li>@Html.ActionLink(item.IName,"Browse", new { item = item.IName })</li>
}
</ul>
樣本數據
namespace MvcProductsStore.Models
{
public class SampleData : DropCreateDatabaseIfModelChanges<ProductsStoreEntities>
{
protected override void Seed(ProductsStoreEntities context)
{
var items = new List<Item>
{
new Item {ItemId = 1000, IName = "Patches"},
new Item {ItemId = 2000,IName = "Jewelry"},
new Item {ItemId = 3000, IName = "Wood Working"}
};
items.ForEach(s => context.item.Add(s));
}
}
模式
namespace MvcProductsStore.Models
{
public class ProductsStoreEntities : DbContext
{
public DbSet<Product> products { get; set; }
public DbSet<Item> item { get; set; }
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
計數
不是真的返回錯誤,但是當我點擊商店時,它告訴我從0項中選擇。因此,而不是拿起它得到的0
添加保存消息並更改返回PartialView返回視圖還有什麼我失蹤仍然給我從0項中選擇。 – user3543447