开发者

Unable to resolve uploaded images paths in partial view on server

My ASP.NET MVC web app requires the upload of image files. These image files are then displayed via a partial view rendering where the path of the image file is inserted into the scr parm of the image tag. This works great in development mode however when I deploy to the server the images won't display. I have tried many way to specify the path including ResolveClientUrl to no avail. As a test I hard coded the path o开发者_运维问答f some images that were not uploaded but part of the original content and they display fine from the server. Here is the partial with some additiona image tags inserted for testing. Again all display fine on my local dev environment but when deployed to the server don't. I have set an alert to capture what is returned from my partial view and the paths look fine. Please any suggestions appreciated.

 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
 <%@ Import Namespace="ULS_Site.Models"%>

   <table>

<%string equipID = ""; %> ' /> <% foreach (var item in ViewData.Model as IEnumerable) %> <%{%> " alt=" " /> <%equipID = item.entity_id;%> )" value="Delete" style="width:45px; font-size:11px" />

<%}%>


You should use Html.Image helper method. That resolves the path for you.

<%= Html.Image(“myImage”, “~/Content/yourImage.jpg”, “A picture of you”) %>

Ref: http://stephenwalther.com/blog/archive/2009/02/18/asp.net-mvc-tip-47-ndash-using-resolveurl-in-an-html.aspx (it's in his book too).


Thanks David _I will check into that however I discovered the issue was with the name of my image folder 'equip_Images'. Once I changed it to equipImages' my issue was resolved. It was strange because as I said in my original post - this was not a problem on my dev machine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜