使用 T4MVC 指定部分视图路径
我在 ASP.NET MVC 项目中使用 T4MVC。
我的观点是这样的:
<% Html.RenderPartial(MVC.SomeController.Views.PartialViewName); %>
以前是这样的:
<% Html.RenderPartial("../SomeController/PartialViewName"); %>
以前它工作正常,但是在我使用 T4MVC 指定部分视图之后,它无法找到该部分视图。
它只是试图在下面的路径中找到它,这是默认行为。
~/Views/SomeController
~/Views/Shared
有没有办法通过 T4MVC 指定位于其他控制器的视图文件夹中的部分视图?或者无论我在做什么,它是正确的吗?我缺少什么?
谢谢。
I am using T4MVC in our ASP.NET MVC project.
I have a statement like this in my view:
<% Html.RenderPartial(MVC.SomeController.Views.PartialViewName); %>
Which was previously like this:
<% Html.RenderPartial("../SomeController/PartialViewName"); %>
Previously it was working fine, but after I specified the partial view using T4MVC, its not able to locate that partial view.
Its Just trying to find it in the below paths, which is the default behaviour.
~/Views/SomeController
~/Views/Shared
Is there a way to specify a partial view which is in some other controller's views folder through T4MVC? or Whatever I am doing, is it correct ? What am I missing ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法 - 您可以扩展视图引擎并使其了解特定的部分视图位置。我自己将所有部分视图放在
Views/Home/Partial
(其中Home
=>controller name)文件夹中。但听起来更多的是你的应用程序结构是错误的。控制器特定的部分视图不应呈现与另一个控制器绑定的部分视图。将这些部分视图放在共享文件夹中。
One approach - you can extend your viewengine and make it aware about specific partial view locations. I myself put all partial views in
Views/Home/Partial
(whereHome
=>controller name) folder.But it sounds more that you are structuring your app wrong. Controller specific partial views should not render partial views that are tied with another controller. Put those partial views in shared folder.
您可能已经知道,我已更改 T4MVC 以生成视图的完整路径而不是短名称。所以上面的原始代码应该可以工作。如果您遇到问题,请告诉我。
这是版本 2.6.03。 下载页面。
As you may already know, I have changed T4MVC to generate the full path to the view instead of the short name. So the original code you have above should just work. Let me know if you run into issues.
This is in build 2.6.03. Download Page.