在ASP.NET MVC网站覆盖视图不工作 [英] Override view in ASP.NET MVC site not working
问题描述
我在我的解决方案单独的项目,它包含了一些控制器和编译意见。
我使用的基类其他控制器的控制器在我的MVC应用程序和看法正在使用RazorGenerator编译。
I have a separate project in my solution that contains some Controllers and compiled views. I use those controllers for base classes to other controllers in my MVC application and the views are compiled using RazorGenerator.
让我们说的乙是基本控制器与非抽象操作方法的 SomeAction 返回查看(_ MyView的)。 _MyView.cshtml 使用RazorGenerator编译。的
Lets say B is Base Controller with non abstract action method SomeAction that returns View("_MyView"). _MyView.cshtml is compiled using RazorGenerator.
可以说,控制器的 A 继承的乙,但不会覆盖 SomeAction
Lets say controller A inherits B but doesn't override SomeAction.
我试图让另一种观点的〜/查看/ A / _MyView.cshtml以覆盖默认之一,但它不工作。我的问题是我怎么能做到这一点?
I've tried to make another view "~/Views/A/_MyView.cshtml" to override the default one, but it doesn't work. My question is how can I accomplish this?
其他信息
1)我知道,在默认情况下该视图搜索的顺序在这些路径
1) I know that the views by default are searched in that order in those paths
"~/Views/{1}/{0}.cshtml",
"~/Views/{1}/{0}.vbhtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/Shared/{0}.vbhtml"
2)把〜/查看/共享/ _MyView.cshtml并覆盖观点,但不仅对控制器的 A ,但也为所有其他控制器继承
乙
2) Putting "~/Views/Shared/_MyView.cshtml" does override the view, but not only for controller A, but also for every other controller that inherits B
3)重写SomeAction返回base.SomeAction()不工作
3) Overriding SomeAction to return base.SomeAction() doesn't work
更新
我已经在这里发现了类似的问题,但这样做的建议什么都没有发生
RazorGenerator问题
I have found similar question here, but doing the suggestion nothing happened RazorGenerator Issues
我已经张贴了我自己的问题,这里
I have posted my own issue here
感谢你在前进!
推荐答案
到目前为止,我唯一的解决办法就是对消费者的应用程序安装RazorGenerator并且还设置视图_MyView.cshtml作为是RazorGenerated。 RazorGenator然后拿起正确的看法。
So far my only workaround is to install RazorGenerator on the consumer app and to also set the view _MyView.cshtml as being RazorGenerated. RazorGenator then picks up the correct view.
的其他游客的另一个需要注意的是不要与路线将基本控制器,而不是消费者控制器化合物中的错误观点的混乱。在早期解决这个问题能够找出实际的错误观点正在被正确的控制器作为OP供应,我有一个问题。我有code在我的基地的Application_Start,消除重复的路线。的
这篇关于在ASP.NET MVC网站覆盖视图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!