我想通过路径显示照片,像\\94.19.247.273\C$\\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg
这样保存在数据库中。
我有mothod
要转换路径
public FileContentResult ImagePath(string path)
{
string str1 = "C:/";
string str2 = "//94.19.247.273/C$//";
string result = path.Replace(str2, str1);
byte[] imageArray = System.IO.File.ReadAllBytes(result);
return new FileContentResult(imageArray, "image/png");
}
我是这样从Stackoverflow和View
上获得的
@foreach (var item in Model.ProductPhotoPathList)
{
<li data-thumb="@Url.Action("ImagePath","Home",new { path = item})">
<div class="thumb-image"> <img src="@Url.Action("ImagePath","Home",new { path = item})" data-imagezoom="true" class="img-responsive" alt=""> </div>
</li>
}
但是当页面加载ImagePath
方法成功工作但在页面上我仍然会得到保存在数据库\\94.19.247.273\C$\\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg
上的路径时,这是一个问题,因此我无法在页面。我想要这样的路径:C:\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg
可能是什么问题?
我有这条路
/Home/ImagePath?path=%2F%2F94.19.247.273%2FC%24%2F%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg
。
所以我想将其转换为/Home/ImagePath?path=C%3A%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg
。
该方法将其正确转换,但我无法在页面上获取它。
答案 0 :(得分:0)
Str1和str2使用正斜杠(/),您的路径具有反斜杠(\)
答案 1 :(得分:0)
1)将其添加到剃须刀的顶部
@{
var split = "httpdocs/";
}
2)然后将您的li
更改为
<li data-thumb="@Url.Content("~/" + item.Substring(item.IndexOf(split) + split.Length))">
<div class="thumb-image"> <img src="@Url.Content("~/" + item.Substring(item.IndexOf(split) + split.Length)) " data-imagezoom="true" class="img-responsive" alt=""> </div>
</li>