示例#1
0
        /// <inheritdoc />
        /// <remarks>Does nothing if user provides an <c>href</c> attribute.</remarks>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (output.Attributes.ContainsName(Href))
            {
                if (Content != null || ContentId != null)
                {
                    throw new InvalidOperationException("You can't supply a href and content/contentid");
                }
            }
            else
            {
                if (Content != null && ContentId != null)
                {
                    throw new InvalidOperationException("You can't supply both content and contentId");
                }

                if (Content != null)
                {
                    output.Attributes.Add(Href, Content.GetContentFullUrlSlug());
                }
                else
                {
                    output.Attributes.Add(Href, ContentId.GetContentFullUrlSlug());
                }

                var routeValueDictionary = (RouteValueDictionary)null;
                if (_routeValues != null && _routeValues.Count > 0)
                {
                    routeValueDictionary = new RouteValueDictionary(_routeValues);
                }

                var tagBuilder = Generator.GenerateActionLink(ViewContext, string.Empty, null, null, null, null, null, routeValueDictionary, null);
                output.MergeAttributes(tagBuilder);
            }
        }