我已经创建了下面的HTML帮助器类,用于显示图片:自定义助手工作不正常
类:
namespace MvcWebMobile.CustomHelpers
{
public static class CustomHelper
{
public static string Image(this HtmlHelper helper, string id, string url, string alternateText)
{
return Image(helper, id, url, alternateText, null);
}
public static string Image(this HtmlHelper helper, string id, string url, string alternateText, object htmlAttributes)
{
// Create tag builder
var builder = new TagBuilder("img");
// Create valid id
builder.GenerateId(id);
// Add attributes
builder.MergeAttribute("src", url);
builder.MergeAttribute("alt", alternateText);
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
// Render tag
return builder.ToString(TagRenderMode.SelfClosing);
}
}
}
查看:
@Html.Image("img1", "../../Content/images/icons-18-black.png", "logo")
现在,当我在我的视图中使用自定义助手图像不显示,而不是图像以下消息打印在我们身上B页数
<img alt="logo" id="img1" src="../../Content/images/icons-18-black.png" /> <img alt="logo" border="4px" id="img1" src="../../Content/images/icons-18-black.png" />
为什么不ü通过图像的应用相对路径? –
我不明白... –
“〜/ Content/images/icons-18-black.png” –