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 ?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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...)
Just spent 10 minutes wondering why it wasn't working - Close and reopen! "Have you tried turning it off and on again?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.