Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't my Html Helpers have intellisense?

Tags:

asp.net-mvc

I can't get intellisense for my own html helpers. My CustomHtmlHelpers.cs looks like this:

using System.Web.Mvc;
using System.Text;
using System.Web;

    namespace laget.Web.Helpers
    {
        public static class CustomHtmlHelpers
        {
            //MY HELPERS
        }
    }

and in my Web.config:

    <pages>
      <namespaces>
        <add namespace="laget.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages"/>
        <add namespace="System.Web.Helpers" />
      </namespaces>
    </pages>

If I put <@using laget.Web.Helpers> in my view, I get the intellisense issue fixed.

Should it not be enough with the code in Web.config?

like image 789
MikeB Avatar asked Feb 24 '11 20:02

MikeB


3 Answers

Sometimes it doesn't seem to work right away. Try closing the .cshtml file, and re-opening it. Then if that doesn't work, try restarting Visual Studio. Also make sure you actually compiled your project, intellisense won't work with non-compiled helpers.

like image 121
Lukáš Novotný Avatar answered Dec 30 '22 17:12

Lukáš Novotný


I'm pretty sure that you're not editing the correct Web.config file.

You need to add your namespace to the one in your Views directory.

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
      <add namespace="laget.Web.Helpers" />
    </namespaces>
  </pages>
</system.web.webPages.razor>
like image 41
Bertrand Marron Avatar answered Dec 30 '22 19:12

Bertrand Marron


You actually don't need to restart Visual Studio in most cases. All you need to do is close the .cshtml file and reopen it!

like image 38
Alexandros B Avatar answered Dec 30 '22 17:12

Alexandros B