我正在尝试从 C# 后端构建无序列表。这是我试图实现的结构:
<li><a href="url.com"><img src="../images/most/most05.jpg" alt="" /><br />LinkName</a></li>
使用此代码:
foreach (Product prod in productList)
{
HtmlGenericControl li = new HtmlGenericControl("li");
products.Controls.Add(li);
string productURL = SEOHelper.GetProductUrl(prod);
HtmlGenericControl anchor = new HtmlGenericControl("a");
anchor.Attributes.Add("href", productURL);
HtmlGenericControl image = new HtmlGenericControl("img");
var productPicture = prod.DefaultProductPicture;
if (productPicture != null)
{
image.Attributes.Add("src", PictureManager.GetPictureUrl(productPicture.Picture, 110, true));
}
else
{
image.Attributes.Add("src", PictureManager.GetPictureUrl(productPicture.Picture, 110, true));
}
anchor.InnerText = prod.Name;
li.Controls.Add(image);
li.Controls.Add(anchor);
}
我得到这个结构:
<li><img src="http://localhost:22621/images/thumbs/0000724_110.jpg"></img><a href="url.com">LinkName</a></li>
如何调整代码以达到我想要的效果?