我正在尝试使用Dojo Dialog来显示图像,但是我的代码背后或前端有问题。我认为这是内容类型的问题。
public ActionResult GetUploadedFile(int FileUploadId)
{
var photos = new GenericRepository<FileUpload>().Find(x => x.FileUploadId == FileUploadId);
if (photos.Any())
{
var photo = photos.First();
Response.AppendHeader("Content-Type", "image/jpeg");
return File(new WebImage(photo.Path).GetBytes(), "image/jpeg");
}
// Loading a default photo for realties that don't have a Photo
return File(new WebImage(HostingEnvironment.MapPath(@"~/Content/images/no-photo100x100.png")).GetBytes(), "image/png");
}
有人可以帮助我吗?
答案 0 :(得分:1)
我认为你的代码是这样的,
<div data-dojo-type="dijit/Dialog" data-dojo-id="showFileDialog" title="Show Files">
<img src="<% Response.write( GetUploadedFile(1234) ) %>"/>
</div>
但是对于你的情况,它应该是那样的
<div data-dojo-type="dijit/Dialog" data-dojo-id="showFileDialog" title="Show Files">
<img src="viewFile.aspx?file_id=1234"/>
</div>
此外,您可以使用数据URI,这里是示例代码,
var image = new WebImage(@"~\images\myImage.jpg");
var base64string = Convert.ToBase64String(image.GetBytes());
....
<img src="data:image/jpg;base64,<% Response.write(base64string) %>" />