3

I have some custom Html helpers for my Asp.net MVC 3 app. In the main application they work correctly as I have put the following in my Web.Config:

<pages clientIDMode="AutoID">
  <namespaces>
    <add namespace="System.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="WebDibaelsaMVC.Utils.HtmlHelpers" />
    <add namespace="WebDibaelsaMVC.Utils.HtmlHelpers.DTOs" />
  </namespaces>
</pages>

but I have now created an area and to make my custom helpers work I have to add a using in every page where I use them. Is there a way to add the default namespaces for that area?

1 Answer 1

5

If you are using Razor you might need to add the reference to the <namespaces> section in the ~/Views/web.config and ~/Areas/YourAreaName/Views/web.config and not the main ~/web.config file. Also make sure you recompile the project, open close the view, maybe even restart Visual Studio for changes to take effect (in terms of Intellisense, it will work if you run the project).

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

3 Comments

Thanks. That was it. I had added them in the main Views but not in the area.
@Carles Company, I am glad I could help.
Had this same issue with the Reactjs.NET html helper not working within an MVC area, and adding the namespace solved it.

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.