开发者

Renaming _ViewStart.cshtml

Is it possible to configure Razor to look for "master" layout files named other than _ViewStart.cshtml? I mean, without explicitly setting the Layout property in the content templates.

In the project I'm working on, each area has its own _ViewStart.cshtml. On top of them there's a "global" _ViewStart.cshtml. This works fine, but I think it would be more convenient if I could assign different names for each master template, like calling the "global" template _GlobalViewStart.cshtml. That way it would be easier to spot each file when there开发者_如何转开发 are many of them open on the Visual Studio ribbon. (Silly? Perhaps.)

If it's possible, how can one do it?

Thanks.


It's hard coded in the RazorViewEngine as "_ViewStart" so I doubt it unless you compile your own version.

public class RazorViewEngine : BuildManagerViewEngine {
    internal static readonly string ViewStartFileName = "_ViewStart";
}

You could define your own base View that changes Layout to whatever you want so you don't have to modify it on every view.


Umm, just saying but isn't the whole point of _ViewStart that its a central place to define settings for all pages (in the area). Note this doesn't mean its a masterpage.

Normally you would specify the default masterpage for the area in _ViewStart, by default this is _Layout (which is your masterpage)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜