简体   繁体   中英

Using string format for Url.Content doesn't work

I have this little foreach statement in an ASPX page:

<%
foreach(string path in pathList)
{
%>
   <img src="<%=Url.Content(string.Format("~/Content/Images/{0}", path))%>" />
<%
}
%>

I want that to display all images using Url.Content from the list of paths.

But my code doesn't work.

In the generated HTML, the above code returns me <img src='/Content/Images/' /> instead of <img src='/Content/Images/page.png' /> and others.

Thanks

You forgot to close the tag

 <img src="<%=Url.Content(string.Format("~/Content/Images/{0}", path)) %>" />

ALso, are you sure the the path really has the value of 'page.png' ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM