2

I've been following tutorials for this, and I've been trying to make this work for the past hour and i don't see where my mistake is so here you go: I have a extention method in a project file:

namespace TomApps.Toolbox.MVC.Security
{
    public static class HtmlExtention
    {
        public static MvcHtmlString GenerateSecureDataControls<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
        {
...
}}

I put in my webconfig:

<system.web>
    <customErrors defaultRedirect="/Home/Index"
                    mode="On">
      <error statusCode="404" redirect="error" />
    </customErrors>
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages controlRenderingCompatibilityVersion="4.0">
      <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.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        **<add namespace="TomApps.Toolbox.MVC.Security"/>**
      </namespaces>
      <controls>
        <add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" />
      </controls>
    </pages>

yet, if i don't put

@using TomApps.Toolbox.MVC.Security 

in my view, i cannot use it:

 @Html.GenerateSecureDataControls(model => model.RoleId)

At first i thought i I was because myname was conflicting, but i saw i made a mistake typing extension :) Any idea of what's wrong? Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
Tom
  • 944
  • 1
  • 14
  • 26

1 Answers1

4

It needs to be under <system.web.webPages.razor>.. as below:

<system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
            <add namespace="TomApps.Toolbox.MVC.Security"/>
        </namespaces>
    </pages>
</system.web.webPages.razor>
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
  • Jesus i suck... I've tried that but created conflicts, so it didn't work.... Thank you! – Tom Nov 22 '12 at 10:01
  • Sorry it wasn't working (or i didn't do it corretly). But i saw that i wasn't modifying the right webconfig, i was updating the root webconfig.. I added in the Views/Web.config and it worked right away.. (http://stackoverflow.com/questions/3875207/how-to-add-extra-namespaces-to-razor-pages-instead-of-using-declaration) – Tom Nov 22 '12 at 10:14