当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.Content方法代码示例

本文整理汇总了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);
        }
开发者ID:anlugifa,项目名称:BootWrapper,代码行数:25,代码来源:MvcHtmlExtentions.cs

示例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));
        }
开发者ID:prabhakara,项目名称:Dexter-Blog-Engine,代码行数:8,代码来源:HtmlHelperHelper.cs

示例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));
        }
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:14,代码来源:Image.cs

示例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);
 }
开发者ID:Interation,项目名称:Interation,代码行数:6,代码来源:HtmlHelperExtension.cs

示例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);
 }
开发者ID:Interation,项目名称:Interation,代码行数:6,代码来源:HtmlHelperExtension.cs


注:本文中的UrlHelper.Content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。