ASP.NET MVC 4 namespace issue in razor view

asp.net-mvc-4, namespaces

Solution

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.

Problem

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 ?

Original source