Can I view .html files using Razor Intellisense as if they were .cshtml files in Visual Studio 2010?

白昼怎懂夜的黑 提交于 2020-01-14 18:53:46

问题


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?


回答1:


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

File: RazorDebugHelpers.cs

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

File: RazorCodeLanguage.cs

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

File: PreApplicationStartCode.cs

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

And so on.

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.



来源:https://stackoverflow.com/questions/10526671/can-i-view-html-files-using-razor-intellisense-as-if-they-were-cshtml-files-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!