9

I've added the following namespace to my Views web.config file:

<add namespace="System.Web.Mvc.Html5" />

Now the issue is that in the Views, I can only use the types using the fullname:

@System.Web.Mvc.Html5.InputTypes.Html5TextBox()

I'd like to be able to do:

@InputTypes.Html5TextBox()

How can I do that ?

Sam
  • 13,934
  • 26
  • 108
  • 194

1 Answers1

31

Make sure you have added this namespace to the ~/Views/web.config file and not to the standard ~/web.config file:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.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.Optimization"/>
        <add namespace="System.Web.Routing" />

        <add namespace="System.Web.Mvc.Html5" />
      </namespaces>
    </pages>
</system.web.webPages.razor>

Also make sure that after adding this namespace you have closed and reopened your Razor view in Visual Studio for the changes to have taken effect.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 13
    I can't believe it was as simple as closing and reopening the view.... Thanks ! (I wonder though why the view can't be refreshed automatically at compile time, whatever...) – Sam Feb 01 '13 at 09:58
  • Just spent 10 minutes wondering why it wasn't working - Close and reopen! "Have you tried turning it off and on again?" – jamheadart Feb 09 '19 at 07:42