0

他のフォルダの PartialViews に Html.RenderPartial を使用するには?

私は次のように試しました:

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

エラーが発生しました:

System.InvalidOperationException: The partial view '~/Views/User/Users.ascx' was not found. The following locations were searched: 
    ~/Views/Main/~/Views/User/Users.ascx.aspx 
    ~/Views/Main/~/Views/User/Users.ascx.ascx 
    ~/Views/Shared/~/Views/User/Users.ascx.aspx 
    ~/Views/Shared/~/Views/User/Users.ascx.ascx

ここに欠けているものはありますか、それとも他のフォルダーでパーシャルビューを呼び出すことができませんか?

4

1 に答える 1

0

パーシャル、ビュー、またはマスターページを見つけるためのルールを変更したい場合は、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);
      }
}
于 2010-02-04T10:38:41.077 に答える