System.Web.Mvc.HtmlHelper' does not contain a definition for 'ActionLink'

穿精又带淫゛_ 提交于 2019-11-29 01:07:51

Add this using System.Web.Mvc.Html; on top of your file

John Culviner

Make sure you have the namespace for your extensions class included in your web.config. For example:

namespace MyProject.Extensions
{
    public static class LinkExtensions
    {
        //code
    }
}

In your site Web.config and/or Web.config located in your "Views" folder:

  <system.web>
    <pages>
      <namespaces>
        <add namespace="MyProject.Extensions" />
      </namespaces>
    </pages>
  </system.web>

Otherwise include a "using" block for the namespace at the top of your view page can work but for common namespaces I would do the above.

ASPX:

<%@ Import namespace="MyProject.Extensions" %>

RAZOR:

@using MyProject.Extensions

Make sure that you have following using in your class file:

using System.Web.Mvc.Html;

This is needed because the HtmlHelper class is located in System.Web.Mvc namespace but the ActionLink extension method is located in System.Web.Mvc.Html namespace.

If your using nopcommerce add this using statement at the top of your view file.

@using Nop.Web.Framework.UI

My issue was, I had incomplete syntax, "@Html.actionLink", in a view. Looks like I had started to add an action link and went a different direction but forgot to remove the partial action link, this caused the same error as above.... So check your syntax as that will throw the same runtime error. Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!