Problem recognizing html helpers in asp.net mvc 3 razor

后端 未结 4 688
眼角桃花
眼角桃花 2021-01-05 00:20

This is what my Html helper looks like:

namespace WebApp.WebUI
{
    public static class HtmlExtensions
    {

            public static MvcHtmlString Genera         


        
相关标签:
4条回答
  • 2021-01-05 00:29

    You could add:

    @using WebApp.WebUI
    

    on the top of your Razor view.

    And if you want to reuse this helper among many different views to avoid adding the using clause everytime you could add it to the <namespaces> section of the ~/Views/web.config file:

    <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="WebApp.WebUI" />
            </namespaces>
        </pages>
    </system.web.webPages.razor>
    

    After doing this make sure you recompile and reopen the Razor view for the Intellisense to have time to pick it up.

    0 讨论(0)
  • 2021-01-05 00:40

    To make html helpers work globally, follow Darin Dimitrov's answer. Once that's done, close the .cshtml view and reopen it, the intellisense starts working.

    Reference: Razor - mvc 3 - Namespace to web.config works but intellisense does not recognize extension

    0 讨论(0)
  • 2021-01-05 00:42

    For me I was using Nopcommerce and had to add the using statement @using Nop.Web.Framework.Security.Captcha

    0 讨论(0)
  • 2021-01-05 00:50

    Like Darin said but, in order to use it globally, you probably need to add it to both ~/Views/web.config and ~/web.config section.

    0 讨论(0)
提交回复
热议问题