【发布时间】:2017-12-07 09:13:24
【问题描述】:
我在 asp.net core 找不到和调用我的标签助手时遇到了一些问题。在我将 taghelpers 从单独的程序集 (LC.Tools.Utility.TagHelpers) 移动到 LC.Tools.Utility 之后,即使命名空间是和以前一样。
示例 cshtml:
<lc:css src="styles.min.css" />
<lc:css src="styles.bootstrap.min.css" />
<lc:css src="styles._layout.min.css" />
查看页面来源时,标签完全相同。
_ViewImports.cshtml:
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, LC.Smokers.Albino.TagHelpers
@addTagHelper *, LC.Tools.Utility.TagHelpers
LC.Tools.Utility.TagHelpers.IncludeCssTagHelper.cs(在程序集中 LC.Tools.Utility):
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace LC.Tools.Utility.TagHelpers
{
[HtmlTargetElement("lc:css", Attributes = "src", TagStructure = TagStructure.WithoutEndTag)]
public class IncludeCssTagHelper : Base
{
public IncludeCssTagHelper(IHostingEnvironment env) : base(env) { }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "link";
output.TagMode = TagMode.SelfClosing;
bool isDebug = this.Environment.IsDevelopment() && this.DebugSrc.Length > 0;
string path = "/CSS/";
if (isDebug)
{
path += this.DebugSrc;
if (Utility.IsUrl(this.DebugSrc))
{
path = this.DebugSrc;
}
}
else if (!string.IsNullOrEmpty(this.Src))
{
path += this.Src;
if (Utility.IsUrl(this.Src))
{
path = this.Src;
}
}
output.Attributes.Clear();
output.Attributes.SetAttribute("href", path.ToLower());
output.Attributes.SetAttribute("rel", "stylesheet");
output.Attributes.SetAttribute("type", "text/css");
base.Process(context, output);
}
[HtmlAttributeName("src")]
public string Src { get; set; }
[HtmlAttributeName("debug-src")]
public string DebugSrc { get; set; } = string.Empty;
}
}
我已经尝试从所有项目中删除 bin 和 obj 文件夹,并且 重建整个解决方案并删除并添加对 项目。
有什么想法吗?
【问题讨论】:
标签: c# asp.net-mvc asp.net-core asp.net-core-mvc