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


C# TagBuilder.GenerateId方法代码示例

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


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

示例1: Foo

 public static HtmlString Foo(this HtmlHelper h, string attr, string id, string tagElement)
 {
     var tBuilder = new TagBuilder(tagElement);
     tBuilder.GenerateId(attr + id);
     var c = new HtmlString(tBuilder.ToString());
     return c;
 }
开发者ID:kamaelyoung,项目名称:My-MVC-Blog,代码行数:7,代码来源:CommentHelperExtension.cs

示例2: HtmlTag

        public HtmlTag(string tagName, string id)
        {
            tagBuilder = new TagBuilder(tagName);

            if (!string.IsNullOrEmpty(id))
                tagBuilder.GenerateId(id);
        }
开发者ID:nuub666,项目名称:framework,代码行数:7,代码来源:HtmlTag.cs

示例3: Catalogue

        public static HtmlString Catalogue(this HtmlHelper helper, string id)
        {
            // Create tag builder
            var builder = new TagBuilder("ul");
            StringBuilder innerHtml = new StringBuilder();

            // Create valid id
            builder.GenerateId(id);

            // Render tag
            if (HttpContext.Current.Session["Cart"] != null) // haven't been to db yet
            {
                CartItem[] cart = (CartItem[])HttpContext.Current.Session["Cart"];
                foreach (CartItem item in cart)
                {
                    innerHtml.Append("<li>");
                    innerHtml.Append("<div class='img'>");
                    innerHtml.Append("<img alt='' src='Content/images/");
                    innerHtml.Append(item.Graphic + "' id='Graphic" + item.ProdCd + "' /></div>");
                    innerHtml.Append("<div class='info'><div style='font-size:small;background:#cfcfcf;' id='Name");
                    innerHtml.Append(item.ProdCd + "'>" + item.ProdName + "</div>");
                    innerHtml.Append("<p id='Descr" + item.ProdCd + "' data-description='");
                    innerHtml.Append(item.Description + "'>" + item.Description.Substring(0, 20) + "...</p>");
                    innerHtml.Append("<div class='price'><span class='st'>Our price:</span>");
                    innerHtml.Append("<strong id='Price" + item.ProdCd + "'>");
                    innerHtml.Append(String.Format("{0:C}", Convert.ToDecimal(item.Msrp)));
                    innerHtml.Append("</strong></div><div class='actions'>");
                    innerHtml.Append("<a href=\"#details_popup\" onclick=\"copyProdInfoToPopup('");
                    innerHtml.Append(item.ProdCd + "');\">Details</a></div></div></li>");
                }
            }
            builder.InnerHtml = innerHtml.ToString();
            return new HtmlString(builder.ToString());
        }
开发者ID:elauersen,项目名称:Info3067Case1,代码行数:34,代码来源:CatalogueHelper.cs

示例4: 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

示例5: DropList

        public static string DropList(this HtmlHelper helper, string name, List<SelectListItem> data, object htmlAttributes = null)
        {
            if (data == null && helper.ViewData != null)
                data = helper.ViewData.Eval(name) as List<SelectListItem>;
            if (data == null) return string.Empty;

            var select = new TagBuilder("select");

            if (htmlAttributes != null)
                select.MergeAttributes(new RouteValueDictionary(htmlAttributes));

            select.GenerateId(name);
            select.MergeAttribute("name" , name);

            var optHtml = new StringBuilder();

            foreach (var item in data)
            {
                var option = new TagBuilder("option");
                option.Attributes.Add("value", helper.Encode(item.Value));
                if (item.Selected)
                    option.Attributes.Add("selected", "selected");
                option.InnerHtml = helper.Encode(item.Text);
                optHtml.AppendLine(option.ToString(TagRenderMode.Normal));
            }
            select.InnerHtml = optHtml.ToString();
            return select.ToString(TagRenderMode.Normal);
        }
开发者ID:kakaci123,项目名称:Program-Git-Foundation,代码行数:28,代码来源:DropListExtensions.cs

示例6: BuildRadioButton

        private IHtmlString BuildRadioButton(string name, object value, bool? isChecked, IDictionary<string, object> attributes) {
            string valueString = ConvertTo(value, typeof(string)) as string;

            TagBuilder builder = new TagBuilder("input");
            builder.MergeAttribute("type", "radio", true);
            builder.GenerateId(name);
            builder.MergeAttributes(attributes, replaceExisting: true);

            builder.MergeAttribute("value", valueString, replaceExisting: true);
            builder.MergeAttribute("name", name, replaceExisting: true);

            var modelState = ModelState[name];
            string modelValue = null;
            if (modelState != null) {
                modelValue = ConvertTo(modelState.Value, typeof(string)) as string;
                isChecked = isChecked ?? String.Equals(modelValue, valueString, StringComparison.OrdinalIgnoreCase);
            }

            if (isChecked.HasValue) {
                // Overrides attribute values
                if (isChecked.Value) {
                    builder.MergeAttribute("checked", "checked", true);
                }
                else {
                    builder.Attributes.Remove("checked");
                }
            }

            AddErrorClass(builder, name);

            return builder.ToHtmlString(TagRenderMode.SelfClosing);
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:32,代码来源:HtmlHelper.Radio.cs

示例7: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            TagBuilder table = new TagBuilder("table");
            table.GenerateId(context.UniqueId, "id");
            var attributes = context.AllAttributes.Where(a => a.Name != ItemsAttributeName).ToDictionary(a => a.Name);
            table.MergeAttributes(attributes);

            var tr = new TagBuilder("tr");
            var heading = Items.First();
            PropertyInfo[] properties = heading.GetType().GetProperties();
            foreach (var prop in properties)
            {
                var th = new TagBuilder("th");
                th.InnerHtml.Append(prop.Name);
              
                tr.InnerHtml.AppendHtml(th);
            }
            table.InnerHtml.AppendHtml(tr);
          
            foreach (var item in Items)
            {

                tr = new TagBuilder("tr");
                foreach (var prop in properties)
                {
                    var td = new TagBuilder("td");
                    td.InnerHtml.Append(prop.GetValue(item).ToString());
                    tr.InnerHtml.AppendHtml(td);
                }
                table.InnerHtml.AppendHtml(tr);
            }
            
            output.Content.AppendHtml(table.InnerHtml);
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:34,代码来源:TableTagHelper.cs

示例8: Topic

        public static string Topic(string name, List<Topic> options)
        {
            var select = new TagBuilder("select");
            select.MergeAttribute("style", "background-color: transparent;");
            select.MergeAttribute("name", name);
            select.GenerateId(name);

            var optionBuilder = new StringBuilder();

            foreach (var option in options)
            {
                var optionTag = new TagBuilder("option");
                optionTag.MergeAttribute("value", option.Id.ToString());
                optionTag.MergeAttribute("style",
                    "color: white; background-color: " +
                    ColorTranslator.ToHtml(option.Color));
                optionTag.InnerHtml = option.Name;

                optionBuilder.Append(optionTag.ToString(TagRenderMode.Normal));
            }

            select.InnerHtml = optionBuilder.ToString();

            return select.ToString(TagRenderMode.Normal);
        }
开发者ID:gkeary,项目名称:myGetOrg,代码行数:25,代码来源:ColorDropDownHelper.cs

示例9: GroupBox

			public GroupBox(AjaxHelper ajax, string headerText, string loader)
			{
				_ajax = ajax;

				if (IsAjax)
					return;

				_groupDiv = new TagBuilder("div");
				var headerDiv = new TagBuilder("div");
				_contentDiv = new TagBuilder("div");
				_loadingDiv = new TagBuilder("div");

				_groupDiv.AddCssClass("card");
				headerDiv.AddCssClass("card-header");
				_contentDiv.AddCssClass("card-block");
				_contentDiv.Attributes.Add("style", "position:relative;");
				_loadingDiv.AddCssClass("ajax-overlay");
				_loadingDiv.GenerateId(loader);

				headerDiv.SetInnerText(headerText);


				Write(_groupDiv.ToString(TagRenderMode.StartTag));
				Write(headerDiv.ToString());
				
				Write(_contentDiv.ToString(TagRenderMode.StartTag));

			}
开发者ID:cssack,项目名称:CsGlobals,代码行数:28,代码来源:AjaxExtensions.cs

示例10: TextAreaHelper

        private static string TextAreaHelper(this HtmlHelper htmlHelper, string name, bool useViewData, string value, IDictionary<string, object> implicitAttributes, IDictionary<string, object> explicitParameters, IDictionary<string, object> htmlAttributes) {
            if (String.IsNullOrEmpty(name)) {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "name");
            }

            TagBuilder tagBuilder = new TagBuilder("textarea");
            // Add implicit attributes.
            tagBuilder.MergeAttributes(implicitAttributes);
            tagBuilder.GenerateId(name);
            // Merge htmlAttributes.
            tagBuilder.MergeAttributes(htmlAttributes, true);
            // Override all the attributes with explicit parameters.
            tagBuilder.MergeAttributes(explicitParameters, true);
            tagBuilder.MergeAttribute("name", name, true);

            // If there are any errors for a named field, we add the css attribute.
            ModelState modelState;
            if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState)) {
                if (modelState.Errors.Count > 0) {
                    tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
                }
            }

            // The first newline is always trimmed when a TextArea is rendered, so we add an extra one
            // in case the value being rendered is something like "\r\nHello".
            // The attempted value receives precedence over the explicitly supplied value parameter.
            string attemptedValue = (string)htmlHelper.GetModelStateValue(name, typeof(string));
            tagBuilder.SetInnerText(Environment.NewLine + (attemptedValue ?? ((useViewData) ? htmlHelper.EvalString(name) : value)));
            return tagBuilder.ToString(TagRenderMode.Normal);
        }
开发者ID:ledgarl,项目名称:Samples,代码行数:30,代码来源:TextAreaExtensions.cs

示例11: ToHtmlString

        public override string ToHtmlString()
        {
            string innerText = Text ?? string.Empty;
            string fullName = Name;
            string tagName = TagName.HasValue() ? TagName.ToLower() : "span";

            var tagBuilder = new TagBuilder(tagName);
            if (Encode)
                tagBuilder.SetInnerText(innerText);
            else
                tagBuilder.InnerHtml = innerText;

            tagBuilder.MergeAttributes(HtmlAttributes);

            if (fullName.HasValue())
                tagBuilder.GenerateId(fullName);

            foreach (string cssClass in CssClasses)
                tagBuilder.AddCssClass(cssClass);

            if (CanWrite())
            {
                if (GrantedClass.HasValue())
                    tagBuilder.AddCssClass(GrantedClass);
            }
            else
            {
                if (DeniedClass.HasValue())
                    tagBuilder.AddCssClass(DeniedClass);
            }

            return tagBuilder.ToString(TagRenderMode.Normal);
        }
开发者ID:modulexcite,项目名称:FluentHtml,代码行数:33,代码来源:Element.cs

示例12: TagBuilder

 public virtual TagBuilder 生成标签构造器()
 {
     if (是否已进行过生成) throw new Exception("此对象无法执行多次生成代码操作。");
     var tb = new TagBuilder(标签名称);
     if (!Id.IsNullOrEmpty()) tb.GenerateId(Id);
     if (Css类列表 != null)
     {
         foreach (var f in Css类列表)
         {
             tb.AddCssClass(f);
         }
     }
     if (属性字典 != null)
     {
         foreach (var f in 属性字典)
         {
             tb.Attributes.Add(f.Key, f.Value);
         }
     }
     if (子元素列表 != null)
     {
         foreach (var f in 子元素列表)
         {
             tb.InnerHtml += f.生成代码();
         }
     }
     是否已进行过生成 = true;
     return tb;
 }
开发者ID:manasheep,项目名称:Core3,代码行数:29,代码来源:基本元素.cs

示例13: BuildCheckBox

        private IHtmlString BuildCheckBox(string name, bool? isChecked, IDictionary<string, object> attributes)
        {
            TagBuilder builder = new TagBuilder("input");
            builder.MergeAttribute("type", "checkbox", replaceExisting: true);
            builder.GenerateId(name);
            builder.MergeAttributes(attributes, replaceExisting: true);
            builder.MergeAttribute("name", name, replaceExisting: true);

            if (UnobtrusiveJavaScriptEnabled)
            {
                var validationAttributes = _validationHelper.GetUnobtrusiveValidationAttributes(name);
                builder.MergeAttributes(validationAttributes, replaceExisting: false);
            }

            var model = ModelState[name];
            if (model != null && model.Value != null)
            {
                bool modelValue = (bool)ConvertTo(model.Value, typeof(bool));
                isChecked = isChecked ?? modelValue;
            }
            if (isChecked.HasValue)
            {
                if (isChecked.Value == true)
                {
                    builder.MergeAttribute("checked", "checked", replaceExisting: true);
                }
                else
                {
                    builder.Attributes.Remove("checked");
                }
            }

            AddErrorClass(builder, name);
            return builder.ToHtmlString(TagRenderMode.SelfClosing);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:35,代码来源:HtmlHelper.Checkbox.cs

示例14: Upload

        internal static string Upload(this HtmlHelper htmlHelper, string name, object value, IDictionary<string, object> htmlAttributes)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException("Value cannot be null or empty.", "name");

            var input = new TagBuilder("input");
            input.GenerateId(name + "Upload");
            input.MergeAttribute("name", name + "Upload");
            input.MergeAttribute("type", "file");
            input.MergeAttributes(htmlAttributes);

            string output = string.Format("{0}{1}", htmlHelper.Hidden(name, value), input);

            if (value is string && !string.IsNullOrEmpty(value as string))
            {
                var delete = new TagBuilder("input");
                delete.GenerateId(name + "SqlDelete");
                delete.MergeAttribute("name", name + "SqlDelete");
                delete.MergeAttribute("type", "checkbox");
                delete.MergeAttribute("value", "true");

                output = string.Format("{0} <label>{1} SqlDelete</label>", output, delete);
            }

            return output;
        }
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:26,代码来源:Upload.cs

示例15: 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


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