如何创建一个不会扰乱智能感知的 WebRazorHostFactory?
如果我像这样创建一个新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过在运行时在 Global.asax.cs 的 Application_Start 中更改它来使其工作。
代码如下:
您可能也需要对任何区域执行此操作。
I got it working by changing it at runtime in my Application_Start in Global.asax.cs.
Here's the code:
This would need to be done for any areas you might have as well.
您需要将包含自定义工厂的程序集安装到 GAC 中,以便 Visual Studio 可以使用它。
You need to install the assembly that contains the custom factory into the GAC so Visual Studio can use it.