Reputation: 1689
I have an image tag among a table of several other tds
<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>
In the document.ready
i am using the model property ImagePath
to assign the img src to the image id imgId
$(document).ready(function ()
{
var imgpth = @Html.Raw(Json.Encode(Model.ImagePath));
$('#imgId').attr('src',imgpth);
});
I am getting the path from the database ,
imgpth:`D:\\Myproject\\ResponseImages\\1005\\100526122016151240_1005_0_261216_15_39_53.JPEG`
Let me tell you that the path above is in a different folder from my current application.
i.e. the application running on the server is in folder D:\\MVCProject\\...
where as the images are in the folder D:\\Myproject\\...
But it is not displaying the image, rather it is displaying the default image that is assigned to the image control itself.
EDIT 1
This is my controller code where i am getting the path from,
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);
}
and
ds.Tables[18].Rows[0]["ImagePath"].ToString() has D:\Myproject\ResponseImages\1005\100526122016151240_1005_0_261216_15_39_53.JPEG
Can some one tell if there is something wrong with my approach, either the way the path is being assigned to the imgpth
variable or the jquery code etc??
Upvotes: 2
Views: 109
Reputation: 26
You should be able to use var imgpth = "@Url.Content(Model.ImagePath)"
Upvotes: 1