0

this wont work! its not self closing the html so the image never shows

 [HtmlTargetElement("img", Attributes = "failure-count")]
public class StatusIconTagHelper : TagHelper
{

    public int FailureCount { get; set; }

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {   
        if (FailureCount==0)
        {
            output.Attributes.SetAttribute("src", "~/images/GreenTick.png");             
        }
        else
        {
            output.Attributes.SetAttribute("src", "~/images/RedCross.png");
        }
        output.Attributes.SetAttribute("width", 22);
        output.TagMode = TagMode.SelfClosing;

    }
}

then in the view i have this

<img failure-count="@item.CurrentlyFailed" />

the resultant HTML is this:

<img src="~/images/GreenTick.png" width="22">

So its not closing the html even though its closed in the view and the TagMode=SelfClosing... anyone else seen this?

Joe Bourne
  • 1,144
  • 10
  • 18
  • Just tested your code with IE 11 (.net core 2.0) and it works for me (i.e. produces '/>') – SpruceMoose Sep 20 '17 at 10:23
  • Maybe try updating to a later version of the Microsoft.AspNetCore.Mvc package? Again, I'm using 2.0.0 – SpruceMoose Sep 20 '17 at 10:28
  • I'm using ASP.NET core 2.0 on Visual Studio 2017 15.3.3 with 2.0.0 of MVC – Joe Bourne Sep 20 '17 at 10:36
  • Technically it's not actually required if you have an HTML5 doctype. See https://stackoverflow.com/questions/15149641/do-i-need-a-at-the-end-of-an-img-or-br-tag-etc#15149657. Maybe the image is not displaying because of a 404? – SpruceMoose Sep 20 '17 at 10:49

0 Answers0