1
我在img
文件夾下的ASP.NET項目中包含圖像。我試圖自動化顯示圖像的過程,而不必手動添加每個圖像。無法在文件夾中循環顯示圖像
我想:
@foreach (var image in Directory.GetFiles(Server.MapPath("/img/portfolio/engagement")))
{
<li class="span3"><a href="#" class="thumbnail"><img src="@image"/></a></li>
}
此輸出:
<ul class="thumbnails">
<li class="span3"><a href="#" class="thumbnail"><img src="C:\Users\Cody\Documents\CMBS\CodySolution\CodySolution\img\portfolio\engagement\IMG_0093.jpg"/></a></li>
<li class="span3"><a href="#" class="thumbnail"><img src="C:\Users\Cody\Documents\CMBS\CodySolution\CodySolution\img\portfolio\engagement\IMG_0130.jpg"/></a></li>
<li class="span3"><a href="#" class="thumbnail"><img src="C:\Users\Cody\Documents\CMBS\CodySolution\CodySolution\img\portfolio\engagement\IMG_0144.jpg"/></a></li>
<li class="span3"><a href="#" class="thumbnail"><img src="C:\Users\Cody\Documents\CMBS\CodySolution\CodySolution\img\portfolio\engagement\IMG_9931.jpg"/></a></li>
</ul>
這是行不通的。圖片不顯示,當我嘗試關注直接鏈接時,它告訴我A potentially dangerous Request.Path value was detected from the client (:).
什麼是正在嘗試做的事情?
:這會給你喜歡
http://www.yoursite.com/Content/file.jpg
例如HTTP路徑?這似乎沒有什麼區別。 – Cody
你不需要完整的服務器路徑,只需要文件名。我會更新我的答案。 – Artless