自己写的一个HtmlHelper,之前在ASP.NET 5中可以使用,但升级到ASP.NET Core之后,却出现如下的错误:
error CS1061: 'IHtmlHelper<dynamic>' does not contain a definition for 'TabLink' and no extension method 'TabLink' accepting a first argument of type 'IHtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?) at Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationResult.EnsureSuccessful() at Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.CreateCacheEntry(String normalizedPath, Func`2 compile)
是自己写的HtmlHelper扩张方法忘了改命名空间,由 Microsoft.AspNet.Mvc.Rendering 改为 Microsoft.AspNetCore.Mvc.Rendering ,问题就解决了。
我也碰到类似这个错误,应该不是命名空间的问题?
'IHtmlHelper<dynamic>' does not contain a definition for 'LangTest' and the best extension method overload 'LocalizationHelper.LangTest(HtmlHelper, string)' requires a receiver of type 'HtmlHelper'
------------扩展方法如下------------
using System;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace FoxCRMCore
{
public static class LocalizationHelper
{
public static string LangTest(this HtmlHelper html, string key)
{
return "ddd";
}
}
}
要改成 public static string LangTest(this IHtmlHelper html, string key)