与 razor(cshtml) 共享模板 site.master aspx(c#)
我已将项目升级到 mvc3,并希望保留所有页面并向其中添加新页面。 现在我的问题是,如果我开始使用 razor,如何在 view.aspx(C#) 和 razor 视图(cshtml) 之间共享我的 site.master 模板页面。 这是因为我不想让我的母版页及其代码由于明显的原因而重复。
I have upgraded my project to mvc3 and want to keep all my pages and add new into it.
Now my question is if i start using razor, how can share my site.master template page between view.aspx(C#) and razor views(cshtml).
This is because i do not want to have my master page and its code duplicated for obvious reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Scott Hanselman 对此发表了博客:
他在博客文章中提供了解决方案。
Scott Hanselman blogged about this:
And he provides the solution in his blog post.
您不能将母版页 (.master) 与 razor 视图 (.cshtml) 一起使用。
它们不兼容,剃刀视图需要布局页面才能实现母版页提供的功能。
您可以创建一个与当前主页具有相同标记的布局页面。这实际上不会是重复,因为它们不兼容。
或者更好的是,您可以将所有内容都转换为剃须刀,有一些工具可以帮助自动化该过程。查看 telerik razor 转换器 提供的免费工具
You cannot use Master pages (.master) with razor views (.cshtml).
They are not compatible, razor views require a layout page to achieve what master pages offer.
You could create a layout page that has the same markup with the current master page. This will not really be duplication since they are not compatible.
Or better still you could just convert everything to razor, there are tools available to help automate the process. Check out this free tool by telerik razor converter