Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 对其他视图/文件夹中的文件使用Html.RenderPartial_Asp.net Mvc_Renderpartial - Fatal编程技术网

Asp.net mvc 对其他视图/文件夹中的文件使用Html.RenderPartial

Asp.net mvc 对其他视图/文件夹中的文件使用Html.RenderPartial,asp.net-mvc,renderpartial,Asp.net Mvc,Renderpartial,如何对其他文件夹中的PartialView使用Html.RenderPartial 我试过: <% Html.RenderPartial("~/Views/User/Users.ascx", Model); %> 此处是否缺少任何内容或无法在其他文件夹中调用partialview?如果要更改查找partials、vieww或MasterPage的规则,必须更改ViewEngine public class ChangedWebFormViewEngine : WebFormView

如何对其他文件夹中的PartialView使用Html.RenderPartial

我试过:

<% Html.RenderPartial("~/Views/User/Users.ascx", Model); %>

此处是否缺少任何内容或无法在其他文件夹中调用partialview?

如果要更改查找partials、vieww或MasterPage的规则,必须更改ViewEngine

public class ChangedWebFormViewEngine : WebFormViewEngine
{

      private static string[] LocalViewFormats = 

       new string[] {
           "~/Views/{1}/OtherPath/{0}.aspx",
        "~/Views/{1}/{0}.aspx",
        "~/Views/{1}/{0}.ascx",
        "~/Views/Shared/{0}.aspx",
        "~/Views/Shared/{0}.ascx"
    };

      public LocalizationWebFormViewEngine()
      {      
        base.ViewLocationFormats = LocalViewFormats;
         base.PartialViewLocationFormats = LocalViewFormats;
         base.MasterLocationFormats = new string[] {

              "~/Views/{1}/OtherPath/{0}.master",
              "~/Views/{1}/{0}.master",
               "~/Views/Shared/OtherPath/{0}.master",
                "~/Views/Shared/{0}.master"
          };
    }



      protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
      {
          return new LocalizationWebFormView(viewPath, masterPath);
      }

      protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
      {
          return new LocalizationWebFormView(partialPath, null);
      }
}

在不覆盖ViewEngine的情况下是否无法使用?有点像,但它会出错。我不这么认为。在错误中可以看到搜索的路径。为了好玩,你可以试试.././User/Users.ascx,但那真的很乱。覆盖viewengine没有什么可怕的。
public class ChangedWebFormViewEngine : WebFormViewEngine
{

      private static string[] LocalViewFormats = 

       new string[] {
           "~/Views/{1}/OtherPath/{0}.aspx",
        "~/Views/{1}/{0}.aspx",
        "~/Views/{1}/{0}.ascx",
        "~/Views/Shared/{0}.aspx",
        "~/Views/Shared/{0}.ascx"
    };

      public LocalizationWebFormViewEngine()
      {      
        base.ViewLocationFormats = LocalViewFormats;
         base.PartialViewLocationFormats = LocalViewFormats;
         base.MasterLocationFormats = new string[] {

              "~/Views/{1}/OtherPath/{0}.master",
              "~/Views/{1}/{0}.master",
               "~/Views/Shared/OtherPath/{0}.master",
                "~/Views/Shared/{0}.master"
          };
    }



      protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
      {
          return new LocalizationWebFormView(viewPath, masterPath);
      }

      protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
      {
          return new LocalizationWebFormView(partialPath, null);
      }
}