Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 4 namespace issue in razor view

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 ?

like image 476
Sam Avatar asked Feb 01 '13 09:02

Sam


1 Answers

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.

like image 132
Darin Dimitrov Avatar answered Nov 06 '22 09:11

Darin Dimitrov