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


C# TagBuilder.ToString方法代码示例

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


在下文中一共展示了TagBuilder.ToString方法的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: 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

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

示例4: ToString

        public string ToString(UrlHelper url)
        {
            TagBuilder tagBuilder = new TagBuilder("script");

            if (!string.IsNullOrWhiteSpace(Id))
            {
                tagBuilder.Attributes["id"] = Id;
            }

            if (!string.IsNullOrWhiteSpace(Src))
            {
                tagBuilder.Attributes["src"] = Src;
            }

            if (!string.IsNullOrWhiteSpace(Content))
            {
                tagBuilder.InnerHtml = Content;
            }

            if (Criteria != null)
            {
                return Criteria.BeginTag + tagBuilder.ToString(TagRenderMode.Normal) + Criteria.EndTag;
            }
            return tagBuilder.ToString(TagRenderMode.Normal);
        }
开发者ID:yangwen27,项目名称:moonlit,代码行数:25,代码来源:Script.cs

示例5: TagWrapper

 public static HtmlElement TagWrapper(this HtmlHelper h, string tag, object htmlattributes)
 {
     var tb = new TagBuilder(tag);
     tb.MergeAttributes(new RouteValueDictionary(htmlattributes));
     h.ViewContext.HttpContext.Response.Write(tb.ToString(TagRenderMode.StartTag));
     return new HtmlElement() { CloseTag = tb.ToString(TagRenderMode.EndTag), h = h };
 }
开发者ID:ToJans,项目名称:MVCExtensions,代码行数:7,代码来源:HtmlHelperExtensions.cs

示例6: Write

		internal static void Write(HierarchyNode<ContentItem> hierarchy, ContentItem selectedItem, IContentAdapterProvider adapters, ItemFilter filter, string selectableTypes, string selectableExtensions, bool excludeRoot, string target, TextWriter writer)
		{
			N2.Web.Tree.Using(hierarchy)
				.OpenTo(selectedItem)
				.Filters(filter)
				.IdProvider(n => "u" + n.Current.ID, n => "l" + n.Current.ID)
				.LinkWriter((n, w) =>
				{
					BuildLink(adapters.ResolveAdapter<NodeAdapter>(n.Current), n.Current, n.Current.Path == selectedItem.Path, target, IsSelectable(n.Current, selectableTypes, selectableExtensions)).WriteTo(w);
					if (n.Children.Count == 0 && adapters.ResolveAdapter<NodeAdapter>(n.Current).HasChildren(n.Current, filter))
					{
						var ul = new TagBuilder("ul");
						ul.AddCssClass("ajax");
						w.Write(ul.ToString(TagRenderMode.StartTag));

						var li = new TagBuilder("li");
						li.InnerHtml = "{url:" + Url.ParseTokenized("{ManagementUrl}/Content/Navigation/LoadTree.ashx")
							.AppendQuery("target", target)
							.AppendQuery(SelectionUtility.SelectedQueryKey, HttpUtility.UrlEncode(n.Current.Path))
							.AppendQuery("selectableTypes", selectableTypes)
							.AppendQuery("selectableExtensions", selectableExtensions)
							+ "}";
						w.Write(li.ToString());

						w.Write(ul.ToString(TagRenderMode.EndTag));
					}
				})
				.ExcludeRoot(excludeRoot)
				.WriteTo(writer);
		}
开发者ID:rohancragg,项目名称:n2cms,代码行数:30,代码来源:TreeUtility.cs

示例7: MenuItemCheveron

        public static MvcHtmlString MenuItemCheveron(this HtmlHelper htmlHelper,
                                                     string text, string action, string controller,
                                                     string cheveronText, string area = null)
        {
            var li = new TagBuilder("li");
            var routeData = htmlHelper.ViewContext.RouteData;

            var currentAction = routeData.GetRequiredString("action");
            var currentController = routeData.GetRequiredString("controller");
            var currentArea = routeData.DataTokens["area"] as string;
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);

            if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(currentArea, area, StringComparison.OrdinalIgnoreCase))
            {
                li.AddCssClass("active");
            }
            var linkBuilder = new TagBuilder("a");
            linkBuilder.MergeAttribute("href", urlHelper.Action(action, controller));

            var htmlText = li.ToString(TagRenderMode.StartTag);
            htmlText += linkBuilder.ToString(TagRenderMode.StartTag);
            htmlText += text;
            htmlText += linkBuilder.ToString(TagRenderMode.EndTag);
            htmlText += li.ToString(TagRenderMode.EndTag);
            return MvcHtmlString.Create(htmlText.ToString());
        }
开发者ID:sg0193,项目名称:Waterforafrica,代码行数:28,代码来源:HtmlExtensions.cs

示例8: RenderMessages

        /// <summary>
        /// Render all messages that have been set during execution of the controller action.
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <returns></returns>
        public static HtmlString RenderMessages(this HtmlHelper htmlHelper)
        {
            var messages = String.Empty;
            foreach (var notificationType in Enum.GetNames(typeof(NotificationType)))
            {
                var message = htmlHelper.ViewContext.ViewData.ContainsKey(notificationType)
                                ? htmlHelper.ViewContext.ViewData[notificationType]
                                : htmlHelper.ViewContext.TempData.ContainsKey(notificationType)
                                    ? htmlHelper.ViewContext.TempData[notificationType]
                                    : null;
                if (message != null)
                {
                    var divBuilder = new TagBuilder("div");

                    divBuilder.AddCssClass(String.Format("alert alert-dismissable fade in alert-{0}", notificationType.ToLowerInvariant()));

                    var buttonBuilder = new TagBuilder("button");

                    buttonBuilder.AddCssClass("close");
                    buttonBuilder.MergeAttribute("type", "button");
                    buttonBuilder.MergeAttribute("data-dismiss", "alert");
                    buttonBuilder.MergeAttribute("aria-hidden", "true");
                    buttonBuilder.InnerHtml += "&times;";
                    buttonBuilder.ToString(TagRenderMode.EndTag);

                    divBuilder.SetInnerText(message.ToString());

                    divBuilder.InnerHtml += buttonBuilder.ToString();

                    messages = divBuilder.ToString();
                }
            }
            return MvcHtmlString.Create(messages);
        }
开发者ID:sbudihar,项目名称:SIRIUSrepo,代码行数:39,代码来源:NotificationHelper.cs

示例9: Image

		public static MvcHtmlString Image(string source, string alt, object htmlAttributes)
		{
			HttpContext context = HttpContext.Current;

			var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) as IDictionary<string, object>;

			var imageBuilder = new TagBuilder("img");
			imageBuilder.MergeAttribute("alt", alt);
			imageBuilder.MergeAttributes(attributes);

			if (context.Request.Browser.IsMobileDevice)
			{
				source = source.Replace(".", "-mobile.");
				//return String.Format("<image src='{0}' alt='{1}' />", source, alt);
				imageBuilder.MergeAttribute("src", source);
				return MvcHtmlString.Create(imageBuilder.ToString(TagRenderMode.SelfClosing));
			}
			else
			{
				//return String.Format("<image src='{0}' alt='{1}' />", source, alt);
				imageBuilder.MergeAttribute("src", source);

				return MvcHtmlString.Create(imageBuilder.ToString(TagRenderMode.SelfClosing));
			}
		}	
开发者ID:dbvibe,项目名称:MVC-Template,代码行数:25,代码来源:ResponsiveImageHelper.cs

示例10: ReferenceBundle

        private static MvcHtmlString ReferenceBundle(HtmlHelper helper, string bundlePath, TagBuilder baseTag, string key)
        {
            var bundle = BundleTable.Bundles.GetBundleFor(bundlePath);
            if (bundle == null)
                throw new ArgumentException("Invalid Bundle Path", "bundlePath");

            var httpContext = helper.ViewContext.HttpContext;
            if (!BundleConfigurationManager.Ignore(httpContext))
            {
                baseTag.MergeAttribute(key, BundleTable.Bundles.ResolveBundleUrl(bundlePath));
                return new MvcHtmlString(baseTag.ToString());
            }

            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
            var bundleContext = new BundleContext(helper.ViewContext.HttpContext, BundleTable.Bundles, urlHelper.Content(bundlePath));
            var htmlString = new StringBuilder();

            foreach (var file in bundle.EnumerateFiles(bundleContext))
            {
                var basePath = httpContext.Server.MapPath("~/");
                if (!file.FullName.StartsWith(basePath))
                    continue;

                var relPath = urlHelper.Content("~/" + file.FullName.Substring(basePath.Length));
                baseTag.MergeAttribute(key, relPath, true);
                htmlString.AppendLine(baseTag.ToString());
            }

            return new MvcHtmlString(htmlString.ToString());
        }
开发者ID:kouweizhong,项目名称:MvcBundleConfig,代码行数:30,代码来源:HtmlHelperExtensions.cs

示例11: ToHtmlString

        public string ToHtmlString()
        {
            TagBuilder controlGroup = new TagBuilder("div");
            controlGroup.AddCssClass("control-group");
            if (!_fieldIsValid) controlGroup.AddCssClass("error");

            TagBuilder controls = new TagBuilder("div");
            controls.AddCssClass("controls");

            switch (_type)
            {
                case ControlGroupType.textboxLike:
                    controls.InnerHtml = _input;
                    controlGroup.InnerHtml = _label + controls.ToString();
                    break;
                case ControlGroupType.checkboxLike:
                    controls.InnerHtml = _label;
                    controlGroup.InnerHtml = controls.ToString();
                    break;
                default:
                    break;
            }

            return controlGroup.ToString();
        }
开发者ID:joypipi,项目名称:TwitterBootstrapMvc,代码行数:25,代码来源:BootstrapControlGroup.cs

示例12: LabelForState

 /// <summary>
 /// 状态标签
 /// </summary>
 /// <param name="helper"></param>
 /// <param name="text">状态名称</param>
 /// <param name="labelClass">状态样式</param>
 /// <returns></returns>
 public static MvcHtmlString LabelForState(this HtmlHelper helper, string text, string labelClass)
 {
     var builder = new TagBuilder("span");
     builder.MergeAttribute("class", "label " + labelClass);
     builder.InnerHtml = text;
     builder.ToString(TagRenderMode.SelfClosing);
     return MvcHtmlString.Create(builder.ToString());
 }
开发者ID:CBDlkl,项目名称:LiGather,代码行数:15,代码来源:LaberHtmlHelper.cs

示例13: Submit

		/// <summary>
		/// 自定义一个@html.Submit()
		/// </summary>
		/// <param name="helper"></param>
		/// <param name="value">value属性</param>
		/// <returns></returns>
		public static MvcHtmlString Submit(this HtmlHelper helper, string value)
		{
			var builder = new TagBuilder("input");
			builder.MergeAttribute("type", "submit");
			builder.MergeAttribute("value", value);
			builder.ToString(TagRenderMode.EndTag);
			return MvcHtmlString.Create(builder.ToString());
		}
开发者ID:zhangz,项目名称:Toolbox,代码行数:14,代码来源:HtmlExtensions.cs

示例14: Image

 /// <summary>
 /// 自定义一个@html.Image()
 /// </summary>
 /// <param name="helper"></param>
 /// <param name="src">src属性</param>
 /// <param name="alt">alt属性</param>
 /// <returns></returns>
 public static MvcHtmlString Image(this HtmlHelper helper, string src, string alt)
 {
     var builder = new TagBuilder("img");
     builder.MergeAttribute("src", src);
     builder.MergeAttribute("alt", alt);
     builder.ToString(TagRenderMode.SelfClosing);
     return MvcHtmlString.Create(builder.ToString());
 }
开发者ID:dreign,项目名称:Famliy.Finance,代码行数:15,代码来源:HtmlHelper2.cs

示例15: RenderSelectable

        public static string RenderSelectable(this HtmlHelper htmlHelper, string[] selectableIds, object selectableOptions)
        {
            // Render Style
            StringBuilder styles = new StringBuilder();
            for(int i = 0; i < selectableIds.Length; i++)
            {
                styles.Append(RenderSelectableStyle(selectableIds[i]) + "\n    ");
            }

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

            builder.MergeAttribute("type", "text/javascript");

            StringBuilder innerHtml = new StringBuilder();
            innerHtml.Append("\n\t$(function(){");

            if (selectableOptions != null)
            {
                TagBuilder tg = new TagBuilder("a");
                tg.MergeAttributes(new RouteValueDictionary(selectableOptions));

                // Add attributes
                int length = tg.ToString(TagRenderMode.SelfClosing).Length;
                string atts = "";
                if (length > 5)
                    atts = tg.ToString(TagRenderMode.SelfClosing).Replace('=', ':').Replace('"', '\0').Replace(' ', ',').Substring(3, length - 6);
                else
                    atts = string.Empty;

                foreach (var item in selectableIds)
                {
                    innerHtml.Append("\n\t    $('#" + item + "').selectable({" + atts + "});");
                }
            }
            else
            {
                foreach (var item in selectableIds)
                {
                    innerHtml.Append("\n\t    $('#" + item + "').selectable();");
                }
            }

            innerHtml.Append("\n\t});\n    ");

            builder.InnerHtml = innerHtml.ToString();

            StringBuilder ids = new StringBuilder();
            foreach (var id in selectableIds)
            {
                ids.AppendFormat(",{0}", id);
            }

            int len = ids.Length;

            // Render tag
            return styles + builder.ToString(TagRenderMode.Normal);
        }
开发者ID:huaminglee,项目名称:hfoa,代码行数:58,代码来源:SelectableExtensions.cs


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