2

我在我们的 ASP.NET MVC 项目中使用 T4MVC。

在我看来,我有这样的声明:

<% Html.RenderPartial(MVC.SomeController.Views.PartialViewName); %>

以前是这样的:

<% Html.RenderPartial("../SomeController/PartialViewName"); %>

以前它工作正常,但在我使用 T4MVC 指定局部视图后,它无法找到该局部视图。

它只是试图在下面的路径中找到它,这是默认行为。

~/Views/SomeController
~/Views/Shared

有没有办法通过 T4MVC 指定位于其他控制器的视图文件夹中的部分视图?或无论我在做什么,是否正确?我错过了什么?

谢谢。

4

2 回答 2

4

一种方法 - 您可以扩展您的视图引擎并使其了解特定的局部视图位置。我自己将所有部分视图放在Views/Home/Partial(其中Home=> 控制器名称)文件夹中。

 public class ViewEngine : WebFormViewEngine
    {
        public ViewEngine()
        {
            PartialViewLocationFormats = PartialViewLocationFormats
                .Union(new[]
                       {
                           "~/Views/{1}/Partial/{0}.ascx",
                           "~/Views/Shared/Partial/{0}.ascx",
                       }).ToArray();
        }
    }

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.

于 2009-11-10T09:55:49.287 回答
4

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.

于 2009-12-13T16:43:46.960 回答