1

我用图像构建项目,图像src与路径比在 db 中的服务器和图像名称中组合。我需要在 HTML 中组合它们。
这是我的代码

 <asp:ListView ID="ul_LeftMenu" runat="server" ClientIDMode="Static">
 <ItemTemplate >
 <li class="li-LeftMenu">
 <img src="<%=Path %><%# Eval("Image") %>" /><a href="../<%# Eval("Url") %>"><%#Eval("Name") %></a></li>
 </ItemTemplate>
 </asp:ListView> 

<%=Path %>从服务器端

<%# Eval("Image") %>从数据库

如何让一些人这样想

 <img src=" Url.Combine(<%=Path %> ,<%# Eval("Image") %>)"/>

服务器代码

 public string Path { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            Path = "/Master/Images/";

}
4

2 回答 2

1
<img src='<%# new Uri(new Uri(Path), Eval("Image")).AbsoluteUri %>' />
于 2013-08-14T06:08:15.763 回答
0

If you have a base class for your controller, you could copy and paste the code in this answer to be part of your base class.

Otherwise, you can copy the entire Uri class from Codeplex to your project. That will extend the System.Uri with a new Combine() function

于 2014-05-02T03:04:16.990 回答