2017-01-24 120 views
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代码等?

+0

你如何设置你的GET方法ImagePath'的'值(你应该使用'使用Server.Mappath()')? –

+0

@StephenMuecke我在控制器的ActionMethod中设置ImagePath的值。 –

+0

是的,我知道 - 但我问**如何** –

回答

1

您应该能够使用var imgpth = "@Url.Content(Model.ImagePath)"

相关问题