2017-01-24 52 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)"

相關問題