本文整理汇总了C#中UrlHelper.Content方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Content方法的具体用法?C# UrlHelper.Content怎么用?C# UrlHelper.Content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.Content方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActionImage
public static MvcHtmlString ActionImage(this HtmlHelper html, string action, string controllerName, object routeValues, string imagePath, string alt, string confirmMessage, bool newWindow)
{
var url = new UrlHelper(html.ViewContext.RequestContext);
// build the <img> tag
var imgBuilder = new TagBuilder("img");
imgBuilder.MergeAttribute("src", url.Content(imagePath));
imgBuilder.MergeAttribute("alt", alt);
string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
// build the <a> tag
var anchorBuilder = new TagBuilder("a");
anchorBuilder.MergeAttribute("href", url.Action(action, controllerName, routeValues));
anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside
if (!string.IsNullOrEmpty(confirmMessage))
anchorBuilder.MergeAttribute("onclick", "return confirm('" + confirmMessage + "')");
if (newWindow)
anchorBuilder.MergeAttribute("target", "_blank");
string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);
return MvcHtmlString.Create(anchorHtml);
}
示例2: Favicon
public static MvcHtmlString Favicon(this HtmlHelper helper)
{
UrlHelper uh = new UrlHelper(helper.ViewContext.RequestContext);
string faviconUrl = uh.Content("~/Images/favicon.ico");
return new MvcHtmlString(string.Format("<link href=\"{0}\" rel=\"shortcut icon\" type=\"image/x-icon\" />", faviconUrl));
}
示例3: Image
public static MvcHtmlString Image(this HtmlHelper htmlHelper, string imageLocation, string altTag, IDictionary<string, object> htmlAttributes)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);
if (string.IsNullOrEmpty(imageLocation))
throw new ArgumentException("Value cannot be null or empty.", "imageLocation");
var image = new TagBuilder("img");
image.MergeAttributes<string, object>(htmlAttributes);
image.MergeAttribute("src", urlHelper.Content(imageLocation));
image.MergeAttribute("alt", htmlHelper.Encode(altTag));
return MvcHtmlString.Create(image.ToString(TagRenderMode.SelfClosing));
}
示例4: Css
public static void Css(this HtmlHelper htmlHelper, string href)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var element = string.Format("\r\n <link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", urlHelper.Content(href));
htmlHelper.ViewContext.Writer.Write(element);
}
示例5: Javascript
public static void Javascript(this HtmlHelper htmlHelper, string src)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var element = string.Format("\r\n <script src=\"{0}\" type=\"text/javascript\"></script>", urlHelper.Content(src));
htmlHelper.ViewContext.Writer.Write(element);
}