嗨我被困了一个小时来修复从“D:\ Sample”路径检索图像。我正在检索正确的路径,但因为localhost:port“(mylocalhosthere):( port)/D:/Sample/sample1.jpg”而没有显示。如何在项目路径之外显示图像?任何人帮助我。谢谢。这是我的代码:
控制器:
public class UploadController : Controller
{
//
// GET: /Upload/
public ActionResult Index()
{
const string root = @"D:\Sample";
var all = Directory.GetFiles(root).Select(Path.GetFullPath).ToArray();
return View(all);
}
}
}
查看:
@{
ViewBag.Title = "Index";
}
@model string[]
@foreach(var image in Model)
{
var aaa = System.IO.Path.GetFileNameWithoutExtension(image);
<img src="@Url.Content(image)" alt='@aaa'/>
<input type="checkbox" id= '@aaa' />
}