【发布时间】:2017-08-07 11:08:33
【问题描述】:
我正在处理我的MVCOnlineShop 项目,我创建了一个产品列表页面,现在我想为每个产品显示一个图像,所以我在SQL 中创建了一个image 表,其中imageID 和imagepath,在product 表中我添加了imageID,我已经搜索了如何从数据库中获取图像,但不太了解,所以请你帮我看看我的actionresult我的controller?
这是我的productListPartialView:
@model MVCOnlineShop.Models.Category
@{
ViewBag.Title = "ProductList";
}
<script src="~/Scripts/Productjs/bootstrap.min.js"></script>
<script src="~/Scripts/Productjs/jquery.js"></script>
<link href="~/Content/Productcss/bootstrap.min.css" rel="stylesheet">
<link href="~/Content/Productcss/2-col-portfolio.css" rel="stylesheet">
<div class="container">
<!-- Page Header -->
<div class="row">
@foreach (var Product in Model.Products)
{
<div class="col-md-6 portfolio-item">
<a href="#">
<img class="img-responsive" src="http://placehold.it/700x400" alt="">
</a>
<h3>
<a href="#">@Html.ActionLink(Product.ProductName, "Details", new { id = Product.CategoryID })</a>
</h3>
</div>
}
</div>
</div>
此视图将显示每个产品,但使用相同的图像,我想更改它以获取数据库中的图像。
提前致谢 :)
【问题讨论】:
-
你的“product”和“image”表之间是否有外键关系,使用那个“imageID”?那么你的
Product应该有一个 Image 属性,以及你想要的图像路径。 -
我在产品表中添加了 imageID,所以现在每个产品都会有 1 个或多个图像@HansKesting
标签: sql-server asp.net-mvc database entity-framework razor