基本上,我的觀點是試圖同時顯示縮略圖和全尺寸的圖像:力控制器行動回報「類型」的圖片,而沒有以文件
<img src="/Images/GetImage/60?s=1&t=True" class="" style="width: 100px; height: 80px;" data-id="60" data-source="1">
<img src="/Images/GetImage/60?s=1&t=False" class="" style="width: 100px; height: 80px;" data-id="60" data-source="1">
是唯一改變的是t
(縮略圖)布爾值。
- 當我通過真實的,瀏覽器的http請求被解釋爲類型:
jpeg
- 當我通過假的,它被解釋爲
document
請檢查以下PRINTSCREEN:
我該如何強制控制器動作返回類型爲Image
而不是document
?
我實際的源代碼:
public async Task<ActionResult> GetImage(int id, EnumImageSource s, bool t)
{
var backupImagePath = Server.MapPath(Url.Content("~/Content/Images/PhotoNotAvailable.png"));
var originalImagePath = Server.MapPath(Url.Content("~/Content/Images/PhotoNotAvailable.png"));
var finalImagePath = Server.MapPath(Url.Content("~/Content/Images/PhotoNotAvailable.png"));
...
...
...
...
if (model != null)
{
...
...
...
originalImagePath = model.Object.Path;
}
if (t)
{
var extension = System.IO.Path.GetExtension(originalImagePath);
var thumbImagePath = System.IO.Path.ChangeExtension(originalImagePath, null) + "_thumb" + extension;
if (System.IO.File.Exists(thumbImagePath))
{
finalImagePath = thumbImagePath;
}
else
{
if (System.IO.File.Exists(originalImagePath))
{
int width;
int height;
if (ProcessImage.GetDimentionsByImageType(EnumImageSize.Thumbnail, out width, out height))
{
try
{
if (ProcessImage.ResizeImageFile(width, height, originalImagePath, thumbImagePath))
{
finalImagePath = thumbImagePath;
}
}
catch
{
}
}
}
}
}
else
{
if (System.IO.File.Exists(originalImagePath))
{
finalImagePath = originalImagePath;
}
}
var bytes = System.IO.File.ReadAllBytes(finalImagePath);
Response.ContentType = "image/jpeg";
return File(bytes, "image/jpeg");
}
更新#1
按照要求通過MaKCbIMKo。是的,如果我在縮略圖旁邊顯示完整圖像,那麼它們都會被處理爲「圖像」....但是您可以看到我添加「a」html標籤的方式使用相同的路徑。但是,現在看來lightcase.js以某種方式將它處理爲文檔而不是圖像,可能通過嘗試讀取「路徑擴展名」並將其與圖像匹配或不匹配......我真的認爲這是現在的問題。
<div class="img-wrap">
@if (Model.IsReadOnly == false)
{
<span class="close">×</span>
}
<a href="@(Url.Action("GetImage", "Images", new { area = "", id = i.Id, s = (int)i.ImageSource, t = false }))" data-rel="lightcase:[email protected](Model.SourceId)" class="showcase">
<img src="@(Url.Action("GetImage", "Images", new {area = "", id = i.Id, s = (int) i.ImageSource, t = true}))" class="" style="width: 100px; height: 80px;" data-id="@i.Id" data-source="@((int)Model.ImageSource)" />
</a>
FULL IMAGE
<img src="@(Url.Action("GetImage", "Images", new {area = "", id = i.Id, s = (int) i.ImageSource, t = false}))" class="" style="width: 100px; height: 80px;" data-id="@i.Id" data-source="@((int)Model.ImageSource)" />
</div>
你說的「文件」的意思是,在什麼確切的內容類型做您的瀏覽器報告答案是? – christofr
@christofr嗨,我在問題描述中包含了一個打印屏幕。 – Dryadwoods
我所看到的不僅是'類型',還有'發起者'。如果手動輸入這兩個URL並檢查它們將返回什麼(根本不使用JS)會怎麼樣? (也許這將有助於減少搜索區域)。 – MaKCbIMKo