Alloy.Helpers.HtmlHelpers.BeginConditionalLink C# (CSharp) Method

BeginConditionalLink() public static method

Writes an opening ]]> tag to the response if the shouldWriteLink argument is true. Returns a ConditionalLink object which when disposed will write a closing ]]> tag to the response if the shouldWriteLink argument is true.
public static BeginConditionalLink ( this helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null ) : ConditionalLink
helper this
shouldWriteLink bool
url IHtmlString
title string
cssClass string
return ConditionalLink
        public static ConditionalLink BeginConditionalLink(this HtmlHelper helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null)
        {
            if(shouldWriteLink)
            {
                var linkTag = new TagBuilder("a");
                linkTag.Attributes.Add("href", url.ToHtmlString());

                if(!string.IsNullOrWhiteSpace(title))
                {
                    linkTag.Attributes.Add("title", helper.Encode(title));
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    linkTag.Attributes.Add("class", cssClass);
                }

                helper.ViewContext.Writer.Write(linkTag.ToString(TagRenderMode.StartTag));
            }
            return new ConditionalLink(helper.ViewContext, shouldWriteLink);
        }

Same methods

HtmlHelpers::BeginConditionalLink ( this helper, bool shouldWriteLink, Func urlGetter, string title = null, string cssClass = null ) : ConditionalLink