问题
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