为什么我的ASP.NET Image TagHelper不起作用?

时间:2017-09-20 10:16:23

标签: asp.net razor

这不会工作!它不是自我关闭html所以图像永远不会显示

ERROR ( message:Configuration error 
Filename: \\?\C:\WINDOWS\system32\config\systemprofile\Documents\IISExpress\config\applicationHost.config
Line Number: 0
Description: Cannot read configuration file. )

然后在视图中我有这个

$re = '/\s-\s\d+\.\d+\sMB/'; // example match " - 4.0 MB"
$str = '<a href="http://example.com/a0j8nm5l3wo0" target=_blank>01 song name.mp3 - 2.4 MB</a>
<a href="http://example.com/ic1jfhhzzfth" target=_blank>02 song name.mp3 - 4.0 MB</a>
<a href="http://example.com/zo2nv6bzy6gd" target=_blank>03 song_name.mp3 - 3.3 MB</a>
<a href="http://example.com/5fyony1m4j0w" target=_blank>04 song name.mp3 - 3.5 MB</a>
<a href="http://example.com/3imswet27clg" target=_blank>05 song name.mp3 - 1.9 MB</a>
<a href="http://example.com/ml65j3gpdggv" target=_blank>06 song - name.mp3 - 3.4 MB</a>
<a href="http://example.com/hmuk8il0a04j" target=_blank>07 song name.mp3 - 4.4 MB</a>
<a href="http://example.com/qx81e67ystd3" target=_blank>08 song-name.mp3 - 3.9 MB</a>
<a href="http://example.com/g6fo1s64vzkj" target=_blank>09 song name.mp3 - 3.9 MB</a>
<a href="http://example.com/xo3hw4xyx372" target=_blank>10 song name.mp3 - 3.6 MB</a>
<a href="http://example.com/ivcth22eqygd" target=_blank>11 song-name.mp3 - 3.3 MB</a>';
$subst = '';

$result = preg_replace($re, $subst, $str);

echo $result;  

生成的HTML是:

 [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;

    }
}

所以它没有关闭html,即使它在视图中关闭,而TagMode = SelfClosing ......其他人都看过这个吗?

0 个答案:

没有答案
相关问题