如何创建一个不会扰乱智能感知的 WebRazorHostFactory?

发布于 2024-10-30 17:23:05 字数 1139 浏览 2 评论 0原文

如果我像这样创建一个新的 WebRazorHostFactory:

namespace Test
{
    public class TestMvcWebRazorHostFactory : WebRazorHostFactory
    {
        public override WebPageRazorHost CreateHost(string virtualPath, string physicalPath)
        {
            WebPageRazorHost host = base.CreateHost(virtualPath, physicalPath);

            if (!host.IsSpecialPage)
            {
                return new MvcWebPageRazorHost(virtualPath, physicalPath);
            }

            return host;
        }
    }
}

并在 ~/Views/Web.config 中引用它,如下所示:

<system.web.webPages.razor>
    <host factoryType="Test.TestMvcWebRazorHostFactory" />
    ...
</system.web.webPages.razor>

我的视图文件中的智能感知不再识别“model”和“TextBoxFor”:

@model Test.Models.Person

<div>
    @this.Html.TextBoxFor( x => x.Name )
</div>

How do I make a new WebRazorHostFactory that不会弄乱视图文件中的智能感知吗?

在 MvcWebPageRazorHost 中,我看到他们运行一个函数“GetRidOfNamespace("System.Web.WebPages.Html");”,但我不确定这是否是问题所在?我尝试编写一个不同的类,它与 MvcWebPageRazorHost 执行相同的操作,但没有此功能,但它似乎没有效果。谢谢。

If I create a new WebRazorHostFactory like this:

namespace Test
{
    public class TestMvcWebRazorHostFactory : WebRazorHostFactory
    {
        public override WebPageRazorHost CreateHost(string virtualPath, string physicalPath)
        {
            WebPageRazorHost host = base.CreateHost(virtualPath, physicalPath);

            if (!host.IsSpecialPage)
            {
                return new MvcWebPageRazorHost(virtualPath, physicalPath);
            }

            return host;
        }
    }
}

and reference it in ~/Views/Web.config like this:

<system.web.webPages.razor>
    <host factoryType="Test.TestMvcWebRazorHostFactory" />
    ...
</system.web.webPages.razor>

the intellisense in my view files no longer recognize the "model" and "TextBoxFor" in:

@model Test.Models.Person

<div>
    @this.Html.TextBoxFor( x => x.Name )
</div>

How do I make a new WebRazorHostFactory that doesn't mess up the intellisense in the view files?

In the MvcWebPageRazorHost I see they run a function "GetRidOfNamespace("System.Web.WebPages.Html");", but I'm not sure if this is the problem? I have tried to write a different class that does the same thing as MvcWebPageRazorHost without this function and it seems to have no effect. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城空念 2024-11-06 17:23:05

我通过在运行时在 Global.asax.cs 的 Application_Start 中更改它来使其工作。

代码如下:

        var hostSection = WebConfigurationManager.GetSection(HostSection.SectionName, "/Views") as HostSection;

        if (hostSection != null)
        {
            hostSection.FactoryType = "Type.Name, Assembly";
        }

您可能也需要对任何区域执行此操作。

I got it working by changing it at runtime in my Application_Start in Global.asax.cs.

Here's the code:

        var hostSection = WebConfigurationManager.GetSection(HostSection.SectionName, "/Views") as HostSection;

        if (hostSection != null)
        {
            hostSection.FactoryType = "Type.Name, Assembly";
        }

This would need to be done for any areas you might have as well.

冧九 2024-11-06 17:23:05

您需要将包含自定义工厂的程序集安装到 GAC 中,以便 Visual Studio 可以使用它。

You need to install the assembly that contains the custom factory into the GAC so Visual Studio can use it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文