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


C# TagBuilder.MergeAttribute方法代码示例

本文整理汇总了C#中TagBuilder.MergeAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.MergeAttribute方法的具体用法?C# TagBuilder.MergeAttribute怎么用?C# TagBuilder.MergeAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TagBuilder的用法示例。


在下文中一共展示了TagBuilder.MergeAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImageActionLink

 public static MvcHtmlString ImageActionLink(
     this HtmlHelper helper,
     string imageUrl,
     string altText,
     string actionName,
     string controllerName,
     object routeValues,
     object linkHtmlAttributes,
     object imgHtmlAttributes)
 {
     var linkAttributes = AnonymousObjectToKeyValue(linkHtmlAttributes);
     var imgAttributes = AnonymousObjectToKeyValue(imgHtmlAttributes);
     var imgBuilder = new TagBuilder("img");
     imgBuilder.MergeAttribute("src", imageUrl);
     imgBuilder.MergeAttribute("alt", altText);
     imgBuilder.MergeAttributes(imgAttributes, true);
     var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection);
     var linkBuilder = new TagBuilder("a");
     linkBuilder.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues));
     linkBuilder.MergeAttributes(linkAttributes, true);
     var text = linkBuilder.ToString(TagRenderMode.StartTag);
     text += imgBuilder.ToString(TagRenderMode.SelfClosing);
     text += linkBuilder.ToString(TagRenderMode.EndTag);
     return MvcHtmlString.Create(text);
 }
开发者ID:KirillMehtiev,项目名称:Collective,代码行数:25,代码来源:ImageActionLinkExtention.cs

示例2: BuildWidget

 private static string BuildWidget()
 {
     var widget = new TagBuilder("div");
     widget.MergeAttribute("class", "g-recaptcha");
     widget.MergeAttribute("data-sitekey", ReCaptchaConfiguration.Instance.SiteKey);
     return widget.ToString(TagRenderMode.Normal);
 }
开发者ID:vbatrla,项目名称:ReCaptcha.NET,代码行数:7,代码来源:ReCaptchaHtmlHelper.cs

示例3: CanonicalUrl

        public static MvcHtmlString CanonicalUrl(this HtmlHelper html, string path)
        {
            if (String.IsNullOrWhiteSpace(path))
            {
                var rawUrl = html.ViewContext.RequestContext.HttpContext.Request.Url;
                path = String.Format("{0}://{1}{2}", rawUrl.Scheme, rawUrl.Authority, rawUrl.AbsolutePath);
            }

            path = path.ToLower();

            if (path.Count(c => c == '/') > 3)
            {
                path = path.TrimEnd('/');
            }

            if (path.EndsWith("/index"))
            {
                path = path.Substring(0, path.Length - 6);
            }

            var canonical = new TagBuilder("link");
            canonical.MergeAttribute("rel", "canonical");
            canonical.MergeAttribute("href", path);
            return new MvcHtmlString(canonical.ToString(TagRenderMode.SelfClosing));
        }
开发者ID:postworthy,项目名称:postworthy,代码行数:25,代码来源:HtmlHelperExtensions.cs

示例4: Script

        /// <summary>
        /// Loads a script int the view
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="configKey">configuration key value, configured in appsettings</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public static MvcHtmlString Script(this HtmlHelper htmlHelper, string filePath)
        {
            if (UseContentDeliveryNetwork)
                filePath = filePath.Replace("~", ContentUrlPrefix);

            if (string.Compare(WorkEnvironment, "Development", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                var filePathWithoutMin = filePath.Replace(".min", string.Empty);

                if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(filePathWithoutMin)))
                {
                    filePath = filePathWithoutMin;
                }
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new Exception(string.Format("Mvc3.ContentManagement: Resource not found for {0}", filePath));
            }
            else
            {
                TagBuilder tagBuilder = new TagBuilder("script");
                tagBuilder.MergeAttribute("src", UrlHelper.GenerateContentUrl(filePath, htmlHelper.ViewContext.HttpContext));
                tagBuilder.MergeAttribute("type", "text/javascript");
                return new MvcHtmlString(tagBuilder.ToString());
            }
        }
开发者ID:n2463230,项目名称:MVC4Project,代码行数:34,代码来源:StaticContentHelper.cs

示例5: GetLayout

        public HtmlString GetLayout(object object_for_rendering, string name_prefix, string name_element)
        {
            var layout = new StringBuilder();
            var _object = object_for_rendering as Dictionary<string, object>;
            if (_object == null)
            {
                throw new Exception("Невозможно отрисовать параметр для пользователя.");
            }
            var label_tag = new TagBuilder("label");
            label_tag.MergeAttribute("for", String.Format("{0}_{1}", name_prefix, name_element));
            label_tag.SetInnerText(_object["Name"].ToString());

            var input_tag = new TagBuilder("input");
            input_tag.MergeAttribute("data-val", "true");
            input_tag.MergeAttribute("id", String.Format("{0}_{1}", name_prefix, name_element));
            input_tag.MergeAttribute("name", String.Format("{0}.{1}", name_prefix, name_element));
            input_tag.MergeAttribute("type", "checkbox");
            input_tag.MergeAttribute("value", "true");

            var input_hidden_tag = new TagBuilder("input");
            input_hidden_tag.MergeAttribute("name", String.Format("{0}.{1}", name_prefix, name_element));
            input_hidden_tag.MergeAttribute("type", "hidden");
            input_hidden_tag.MergeAttribute("value", "true");

            var p_tag = new TagBuilder("p");
            p_tag.InnerHtml = label_tag.ToString(TagRenderMode.Normal) +
                              input_tag.ToString(TagRenderMode.SelfClosing) +
                              input_hidden_tag.ToString(TagRenderMode.SelfClosing);
            layout.Append(p_tag.ToString(TagRenderMode.Normal));

            return new HtmlString(layout.ToString());
        }
开发者ID:crashr42,项目名称:Health,代码行数:32,代码来源:RenderingFactory.cs

示例6: GetGoogleMapCanvas

 /// <summary>
 /// Get Google Maps Canvas Tag
 /// </summary>
 /// <returns></returns>
 private static string GetGoogleMapCanvas()
 {
     var canvasBuilder = new TagBuilder("div");
     canvasBuilder.MergeAttribute("id", "map_canvas");
     canvasBuilder.MergeAttribute("style", @"height: 500px");
     return "\n" + canvasBuilder.ToString();
 }
开发者ID:vlaz09,项目名称:AspGoogleMapApi,代码行数:11,代码来源:GoogleMapHelper.cs

示例7: BuildControl

        protected override void BuildControl(System.Web.Mvc.TagBuilder builder, Products.CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            builder.AddCssClass("form-list");

            var itemsHtml = new StringBuilder();
            var i = 0;

            foreach (var item in field.SelectionItems)
            {
                itemsHtml.AppendLine("<li>");

                var radioId = field.Name + "_" + i;
                var radio = new TagBuilder("input");
                radio.MergeAttribute("id", radioId);
                radio.MergeAttribute("type", "radio");
                radio.MergeAttribute("name", field.Name);
                radio.MergeAttribute("value", item.Value);

                var label = new TagBuilder("label");
                label.InnerHtml = item.Text;
                label.AddCssClass("inline");
                label.MergeAttribute("for", radioId);

                itemsHtml.AppendLine(radio.ToString(TagRenderMode.SelfClosing));
                itemsHtml.AppendLine(label.ToString());

                itemsHtml.AppendLine("</li>");

                i++;
            }

            builder.InnerHtml = itemsHtml.ToString();

            base.BuildControl(builder, field, value, htmlAttributes, viewContext);
        }
开发者ID:Kooboo,项目名称:Ecommerce,代码行数:35,代码来源:RadioList.cs

示例8: CreateCustomControl

 private static string CreateCustomControl(string name, Type settingType, object value)
 {
     if (settingType.IsEnum)
     {
         TagBuilder tb = new TagBuilder("select");
         tb.MergeAttribute("id", name);
         tb.MergeAttribute("name", name);
         StringBuilder options = new StringBuilder();
         for (int i = 0; i < Enum.GetValues(settingType).Length; i++)
         {
             string optionText = Enum.GetName(settingType, i);
             TagBuilder optionBuilder = new TagBuilder("option");
             optionBuilder.InnerHtml = optionText;
             if (value != null && optionText == value.ToString())
             {
                 optionBuilder.MergeAttribute("selected", "selected");
             }
             options.Append(optionBuilder.ToString());
         }
         tb.InnerHtml = options.ToString();
         return tb.ToString();
     }
     else
     {
         return null;
     }
 }
开发者ID:xwyangjshb,项目名称:cuyahoga,代码行数:27,代码来源:SectionAdminExtensions.cs

示例9: Image

        //Using Tag Builder

        public static MvcHtmlString Image(this HtmlHelper htmlHelper,
            string src, 
            string altText, 
            string cssClass, 
            string name,
            object htmlAttrib =null)
        {
            TagBuilder tb = new TagBuilder("img");
            tb.MergeAttribute("src", src);
            tb.MergeAttribute("alt", altText);

            //Just a null check, just to avoid any space or blank 
            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                tb.AddCssClass(cssClass);
            }

            HTMLCommonExtensions.AddName(tb,name,"");
            

            tb.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttrib));
            //return HTML encoded string
            return MvcHtmlString.Create(tb.ToString(TagRenderMode.SelfClosing));

        }
开发者ID:rahulsahay19,项目名称:Custom-MVCHTMLHelper,代码行数:27,代码来源:HTMLImageExtension.cs

示例10: Dropdown

        /// <summary>
        /// Render simple 'select' control. <c>IsSelected</c> property 
        /// of items will be used to select option.
        /// </summary>
        /// <param name="items">Items list</param>
        /// <returns>Formatted HTML</returns>
        public static IHtmlString Dropdown(string fieldName, IEnumerable<SelectListItem> items)
        {
            Throw.IfNullArgument(items, "items");

            var tb = new TagBuilder("select");

            tb.MergeAttribute("name", fieldName);
            tb.GenerateId(fieldName);

            var sb = new StringBuilder();
            foreach (var item in items)
            {
                var opt = new TagBuilder("option");
                if(!String.IsNullOrEmpty(item.Value))
                    opt.MergeAttribute("value", item.Value);

                if (item.Selected)
                    opt.MergeAttribute("selected", "selected");

                opt.InnerHtml = item.Text;

                sb.Append(opt.ToString(TagRenderMode.Normal));
            }

            tb.InnerHtml = sb.ToString();

            return MvcHtmlString.Create(tb.ToString());
        }
开发者ID:kamaelyoung,项目名称:Carcass,代码行数:34,代码来源:HtmlRenderer.cs

示例11: Image

 public static MvcHtmlString Image(this HtmlHelper helper, string src, string altText)
 {
     var builder = new TagBuilder("img");
     builder.MergeAttribute("src", src);
     builder.MergeAttribute("alt", altText);
     return  MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
 }
开发者ID:GogoGeorgiev,项目名称:ASP.NET-MVC,代码行数:7,代码来源:MyHelpers.cs

示例12: DropDownList

    /// <summary>
    /// dropdown list
    /// </summary>
    /// <param name="name"></param>
    /// <param name="selectList"></param>
    /// <param name="optionLabel"></param>
    /// <param name="htmlAttributes"></param>
    /// <returns></returns>
    public static string DropDownList(string name, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes)
    {
      var b = new TagBuilder("select");

      b.MergeAttribute("name", name);
      b.MergeAttribute("id", name);
      b.MergeAttributes(new RouteValueDictionary(htmlAttributes));

      var ret = "";
      if (optionLabel != null){
        var option = new TagBuilder("option");
        option.MergeAttribute("value", "");
        option.InnerHtml = optionLabel;

        ret = option.ToString();
      }
      

      foreach (var item in selectList)
      {
        var o = new TagBuilder("option");
        o.MergeAttribute("value", item.Value);
        if (item.Selected){
          o.MergeAttribute("selected", "selected");
        }
        o.InnerHtml = item.Text;
        ret += o.ToString();
      }

      b.InnerHtml = ret;

      return b.ToString();
    }
开发者ID:nahmedsoftsource,项目名称:framework-abdh,代码行数:41,代码来源:Helper.cs

示例13: Image

        public static string Image(this HtmlHelper helper, string id, string url, string alternateText, object htmlAttributes)
        {
            // Instantiate a UrlHelper
            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

            // Create tag builder
            var builder = new TagBuilder("img");

            if (!string.IsNullOrEmpty(id))
            {
                builder.GenerateId(id);
            }

            // Add attributes
            builder.MergeAttribute("src", urlHelper.Content(url));

            if (!string.IsNullOrEmpty(alternateText))
            {
                builder.MergeAttribute("alt", alternateText);
                builder.MergeAttribute("title", alternateText);
            }

            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));

            // Render tag
            return builder.ToString(TagRenderMode.SelfClosing);
        }
开发者ID:evgenyb,项目名称:TELViewer,代码行数:27,代码来源:HtmlHelpers.cs

示例14: SubmitTag

 public static MvcHtmlString SubmitTag(this HtmlHelper helper, string value)
 {
     var builder = new TagBuilder("input");
     builder.MergeAttribute("type","submit");
     builder.MergeAttribute("value",value);
     return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
 }
开发者ID:andyWqh,项目名称:AndyCodeHome,代码行数:7,代码来源:HtmlExtensions.cs

示例15: Breadcrumbs

        public static IHtmlString Breadcrumbs(this HtmlHelper helper, List<BreadcrumbItem> items)
        {
            if (items == null || items.Count < 1)
            {
                return MvcHtmlString.Create(string.Empty);
            }

            TagBuilder olTag = new TagBuilder("ol");
            olTag.MergeAttribute("class", "breadcrumb");

            StringBuilder innerHtml = new StringBuilder();
            foreach (BreadcrumbItem item in items)
            {
                TagBuilder liTag = new TagBuilder("li");
                TagBuilder spanTag = new TagBuilder("span");
                TagBuilder aTag = new TagBuilder("a");
                TagBuilder span2Tag = new TagBuilder("span");

                spanTag.MergeAttribute("itemscope", string.Empty);
                spanTag.MergeAttribute("itemtype", "http://data-vocabulary.org/Breadcrumb");
                aTag.MergeAttribute("href", item.Url);
                aTag.MergeAttribute("itemprop", "url");
                span2Tag.MergeAttribute("itemprop", "title");
                span2Tag.SetInnerText(item.Title);

                aTag.InnerHtml = span2Tag.ToString();
                spanTag.InnerHtml = aTag.ToString();
                liTag.InnerHtml = spanTag.ToString();

                innerHtml.Append(liTag.ToString());
            }
            olTag.InnerHtml = innerHtml.ToString();

            return MvcHtmlString.Create(olTag.ToString());
        }
开发者ID:hiroakit,项目名称:blog,代码行数:35,代码来源:HtmlHelperExtensions.cs


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