本文整理汇总了C#中System.Web.Mvc.UrlHelper.Image方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Image方法的具体用法?C# UrlHelper.Image怎么用?C# UrlHelper.Image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.Image方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyndicationIcons
public static string SyndicationIcons(this HtmlHelper helper, string rssUrl, string atomUrl)
{
StringBuilder html = new StringBuilder();
if (!string.IsNullOrEmpty(rssUrl) || !string.IsNullOrEmpty(atomUrl))
{
UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
html.Append("<div class=\"feed\">");
Action<string, string> addIcon = (type, url) =>
{
string iconUrl = urlHelper.Image("{0}.jpg".FormatWith(type));
html.Append(" <a href=\"{0}\" target=\"_blank\"><img alt=\"{1}\" title=\"{1}\" src=\"{2}\"/></a>".FormatWith(helper.AttributeEncode(url), type, helper.AttributeEncode(iconUrl)));
};
if (!string.IsNullOrEmpty(atomUrl))
{
addIcon("atom", atomUrl);
}
if (!string.IsNullOrEmpty(rssUrl))
{
addIcon("rss", rssUrl);
}
html.Append("</div>");
}
return html.ToString();
}
示例2: GenerateImageLinkInternal
private static string GenerateImageLinkInternal(RequestContext requestContext, string imageName, string altText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> linkHtmlAttributes, IDictionary<string, object> imagelinkHtmlAttributes)
{
var urlHelper = new UrlHelper(requestContext);
string url = urlHelper.Action(actionName, controllerName, routeValues, protocol, hostName);
TagBuilder imageTagBuilder = new TagBuilder("img");
imageTagBuilder.MergeAttribute("src", urlHelper.Image(imageName));
imageTagBuilder.MergeAttribute("alt", altText);
imageTagBuilder.MergeAttributes(imagelinkHtmlAttributes);
TagBuilder tagBuilder = new TagBuilder("a")
{
InnerHtml = imageTagBuilder.ToString(TagRenderMode.SelfClosing)
};
tagBuilder.MergeAttributes(linkHtmlAttributes);
tagBuilder.MergeAttribute("href", url);
return tagBuilder.ToString(TagRenderMode.Normal);
}