首页 新闻 赞助 找找看

ASP.NET Core MVC视图中使用HtmlHelper的问题

0
悬赏园豆:10 [已解决问题] 解决于 2016-03-10 18:01

自己写的一个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)
dudu的主页 dudu | 高人七级 | 园豆:31094
提问于:2016-03-10 17:55
< >
分享
最佳答案
0

是自己写的HtmlHelper扩张方法忘了改命名空间,由 Microsoft.AspNet.Mvc.Rendering 改为 Microsoft.AspNetCore.Mvc.Rendering ,问题就解决了。

dudu | 高人七级 |园豆:31094 | 2016-03-10 18:00
其他回答(1)
0

我也碰到类似这个错误,应该不是命名空间的问题?

'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'

  1. @Html.LangTest("lblCustomer")

------------扩展方法如下------------

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";
        }
    }
}

Gu | 园豆:202 (菜鸟二级) | 2018-04-09 12:32

要改成 public static string LangTest(this IHtmlHelper html, string key)

支持(0) 反对(0) Gu | 园豆:202 (菜鸟二级) | 2018-04-09 13:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册