我可以像使用Visual Studio 2010中的.cshtml文件一样使用Razor Intellisense查看.html文件吗?

我可以像使用Visual Studio 2010中的.cshtml文件一样使用Razor Intellisense查看.html文件吗?

问题描述:

我已经获得了.Net MVC3来像处理.cshtml文件一样处理.html(和其他自定义扩展名),但是VS2010不会突出显示Razor语法或为此显示Intellisense.如何让VS2010将.html文件识别为.cshtml?

I've gotten .Net MVC3 to process .html (and other custom extension) just like a .cshtml file but VS2010 will not highlight the Razor syntax or show Intellisense for it. How do I get VS2010 to recognize .html file as .cshtml?

这不是那么容易.如果您看到 asp.net mvc 3源,则可以在网页文件夹中看到以下内容:

It's not so easy. If you see asp.net mvc 3 source, you can see in webpages folder next things:

文件:RazorDebugHelpers.cs

File: RazorDebugHelpers.cs

// Trim the html part of cshtml or vbhtml
string outputExtension = extension.Substring(0, 3);

文件:RazorCodeLanguage.cs

File: RazorCodeLanguage.cs

private static IDictionary<string, RazorCodeLanguage> _services = new Dictionary<string, RazorCodeLanguage>(StringComparer.OrdinalIgnoreCase) {
        { "cshtml", new CSharpRazorCodeLanguage() },
        { "vbhtml", new VBRazorCodeLanguage() }
    };

文件:PreApplicationStartCode.cs

File: PreApplicationStartCode.cs

WebPageHttpHandler.RegisterExtension("cshtml");
WebPageHttpHandler.RegisterExtension("vbhtml");

以此类推.

我想说什么?扩展逻辑在mvc中非常深入.如果您想执行类似的操作,则可能需要下载源代码,对其进行编辑并构建自定义库,但这非常耗时.也许您可以通过其他方式问您问题,希望对您的问题有更好的解决方案.

What i want to say? Extension logic very deep in mvc. If you want to do something like that you prorably need to download sources, edit them and build custom library, but it's very time expensive. Maybe you can ask you question by other way, I hope exist better solution for your problem.