2012-02-10 130 views
-4
@using System.Configuration 
@using UI.AuctionService 
@using UI.Common 
@using UI.Helpers 

@model UI.Models.AuctionFrontendListViewModel 

@{ 
    ViewBag.Title = "Auction List"; 
} 

<h2>@Model.Title</h2> 

<table> 
    <tr> 
     <th> 
      Image 
     </th> 
     <th> 
      Type 
     </th> 
     <th> 
      Auction title 
     </th> 
     <th> 
      Starts 
     </th> 
     <th> 
      Ends 
     </th> 
     <th> 
      Is featured 
     </th> 
     <th> 
      Bid count 
     </th> 
     <th> 
      Creation time 
     </th> 
     <th></th> 
    </tr> 

@foreach (var auction in Model.Auctions) 
{ 
    var type = string.Empty; 
    if (auction.Auction is LubAuction) 
    { 
     type = "Lowest unique wins"; 
    } 
    else if (auction.Auction is EsfAuction) 
    { 
     type = "Highest wins"; 
    } 

    string imagesFolderPath = HttpContextHelper.GetPathInServer(ConfigurationManager.AppSettings["ImagesFolderPath"]); 
    string itemImagesFolderPath = Path.Combine(imagesFolderPath, ImageType.Item + @"\\" + auction.Auction.InventoryReference); 
    string chosenImage = string.Empty; 
    if (Directory.Exists(itemImagesFolderPath)) 
    { 
     string[] files = Directory.GetFiles(itemImagesFolderPath); 
     if (files.Length > 0) 
     { 
      chosenImage = files[0]; 
     } 
    } 

    <tr> 
     <td> 
      <img src="@chosenImage" /> 
     </td> 
     <td> 
      @type 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => auction.Auction.Title) 
     </td> 
     <td> 
      @DateTimeHelper.LocalDateTime(auction.Auction.Starts) 
     </td> 
     <td> 
      @DateTimeHelper.LocalDateTime(auction.Auction.Ends) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => auction.Auction.IsFeatured) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => auction.Auction.BidCount) 
     </td> 
     <td> 
      @DateTimeHelper.LocalDateTime(auction.Auction.AddedDate) 
     </td> 
     <td> 
      @Html.ActionLink("Details", "Details", new { id = auction.Auction.Id }) 
     </td> 
    </tr> 
} 

</table> 
<div class="pager"> 
@Html.PageLinks(Model.PagingInfo, x => Url.Action(Model.Action, new { page = x })) 
</div> 
+2

請縮小你的問題一點 - 有什麼具體的部分是給你的問題? – eouw0o83hf 2012-02-10 15:02:51

+0

你得到的錯誤是什麼? – 2012-02-10 15:03:53

+0

好吧,問題是我無法在img標籤中顯示圖像。 – 2012-02-10 15:04:41

回答

2

如果圖像是問題,我會建議以不同的方式做。您的剃刀視圖可能不應負責淘洗服務器以查找圖像;考慮通過模型或ViewData將該信息推入視圖。

另外,爲什麼你將@"\\"傳遞給Path.Combine?您正在向路徑添加雙斜槓。讓Path.Combine來處理這個問題。我認爲這可能是你的主要問題。請執行下列操作之一:

string itemImagesFolderPath = Path.Combine(imagesFolderPath, ImageType.Item + @"\" + auction.Auction.InventoryReference); 

,或者更優選

string itemImagesFolderPath = Path.Combine(imagesFolderPath, ImageType.Item, auction.Auction.InventoryReference);