0
筆者認爲:我該怎麼讓與MIXIT插件的瀏覽器,其中圖像鏈接從DB傳來的圖像,但圖像不是在Asp.net MVC應用程序顯示
@model IEnumerable<AdSite.Models.Album>
@{
ViewBag.Title = "Index";
}
<button class="filter btn btn-primary" data-filter=".category-1">Category 1</button>
<button class="filter btn btn-success" data-filter=".category-2">Category 2</button>
<button class="sort btn btn-default" data-sort="my-order:asc">Ascending Order</button>
<button class="sort btn btn-primary" data-sort="my-order:desc">Descending Order</button>
<button class="filter btn btn-success" data-filter=".all">All</button>
<div id="Container">
@foreach (var item in Model)
{
<div class=" mix category-1 all" data-my-order="@item.Id">
<img alt="" src="@item.ProductTitle" />
</div>
}
</div>
@section scripts{
<script src="~/Scripts/App/jquery.mixitup.min.js"></script>
<script>
$(function() {
$('#Container').mixItUp();
});
</script>
}
我的控制器動作:
public ActionResult Index()
{
var db = new AlbumContext();
return View(db.Albums.ToList());
}
我的模型:
public class Album
{
public int Id { get; set; }`
public string ProductTitle { get; set; }
public string Description { get; set; }
}
所以,這是我的代碼。我需要通過瀏覽器中使用的mixit插件顯示圖像。我在這裏使用了一個引用Album model
的視圖,foreach loop
用於獲取ProductTitle
屬性中給出的image
鏈接。另外我上傳image
在項目的Content
文件夾中。當我運行代碼時,圖像鏈接顯示在瀏覽器的源代碼中,但圖像未顯示。我該如何解決它?任何人的幫助表示讚賞。謝謝。
url如何在db中看起來像是相對路徑嗎? –
你好@EhsanSajjad我使用EF代碼的第一個模型。和圖像的URL看起來像這個'「〜/ Content/image/2.jpg」' –
使用Url.Content像 –