registrar dll en mvc razor view

In web forms we can write this code above the page:

<%@ Register Assembly="xxx.CaptchaGenerator" 
Namespace="xxx.CaptchaGenerator" TagPrefix="mycaptcha" %>

Then it can be used:

<mycaptcha:CaptchaControl ID="ccJoin" 
runat="server" CaptchaHeight="31" CaptchaLength="5" />

How can I do this in mvc3, razor? I use this syntax @Using xxx.CaptchaGenerator and add this lines in my web config :

<pages>
  <namespaces>

    <add namespace="xxx.CaptchaGenerator"  />

    <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"/>
  </namespaces>
</pages>

Pero no funcionó.

preguntado el 10 de marzo de 12 a las 08:03

When writing questions, please check the preview before posting. Any html tags must be marked as code or they will not show up in the post. -

2 Respuestas

You could add namespaces to the ~/Views/web.configno, ~/web.config. Por ejemplo:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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.Routing" />

        <add namespace="xxx.CaptchaGenerator"  />
      </namespaces>
    </pages>
</system.web.webPages.razor>

respondido 10 mar '12, 08:03

in question exist TagPrefix property and use it but in this answer not exist it. How do access to CaptchaGenerator in view? - Mohsen

@Mohsen, I don't understand what you are asking. - darin dimitrov

as i know cant use the server control in view(razorengine)..
you can use aspx file and then call it in your parent view with html.partial(aspx fileName)
i know this not a good solution and maybe not correct answer but its useful dear mohsen
شاید راه دیگه ایم باشه

respondido 10 mar '12, 13:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.