2
我有几个其他的TDS表中的图像标签图像不显示在我的MVC应用程序
<table class="MyClass">
<tr>
<td>
@Html.LabelFor(m => m.ShopName)
</td>
<td>
@Html.TextBoxFor(model => model.ShopName, new { @class = "form-control", id = "myid1", @readonly = true, @Enabled = "False" })
</td>
<td>
@Html.TextBoxFor(model => model.ShopName, new { @class = "form-control", placeholder = "Enter ShopName", id = "myid2", @maxlength = "200" })
@Html.ValidationMessageFor(model => model.ShopName)
</td>
<td class="myclass2" rowspan="3">
<a data-toggle="modal" data-target="#cardDialog" href="#"><img src="~/Content/dist/img/card.svg" id="imgId"></a>
</td>
</tr>
</table>
在document.ready
我使用的模型属性ImagePath
分配的IMG SRC的图片ID imgId
$(document).ready(function()
{
var imgpth = @Html.Raw(Json.Encode(Model.ImagePath));
$('#imgId').attr('src',imgpth);
});
我从数据库中获取的路径,
imgpth:`D:\\Myproject\\ResponseImages\\1005\\100526122016151240_1005_0_261216_15_39_53.JPEG`
让我告诉你,上面的路径与我当前的应用程序位于不同的文件夹中。
即在服务器上运行的应用程序文件夹D:\\MVCProject\\...
其中作为图像文件夹D:\\Myproject\\...
中,但它不显示图像,而它显示分配给图像的默认图像控制自己。
EDIT 1
这是我在哪里从得到的路径我的控制器代码,
public ActionResult Index()
{
ResponseObj = new ModelResponseDetails();
//Some other controls data
ResponseObj.ShopName=ds.Tables[18].Rows[0]["ShopName"].ToString();
....
....
....
ResponseObj.ImagePath = ds.Tables[18].Rows[0]["ImagePath"].ToString();
return View(ResponseObj);
}
和 ds.Tables [18] .Rows [0] [ “的ImagePath”] .ToString()有D:\Myproject\ResponseImages\1005\100526122016151240_1005_0_261216_15_39_53.JPEG
有人可以告诉我的方法是否有问题,无论路径被分配到imgpth
变量或jQuery代码等?
你如何设置你的GET方法ImagePath'的'值(你应该使用'使用Server.Mappath()')? –
@StephenMuecke我在控制器的ActionMethod中设置ImagePath的值。 –
是的,我知道 - 但我问**如何** –