0

要件を最もよく説明する方法がわかりませんが、ここで説明します。nopCommerceアプリケーションで次のコントローラー/モデルからビューをレンダリングしようとしています:

CustomerController.csスニペット:

[NonAction]
protected CustomerNavigationModel GetCustomerNavigationModel(Customer customer)
{
   var model = new CustomerNavigationModel();
   model.HideAvatar = !_customerSettings.AllowCustomersToUploadAvatars;
   model.HideRewardPoints = !_rewardPointsSettings.Enabled;
   model.HideForumSubscriptions = !_forumSettings.ForumsEnabled || !_forumSettings.AllowCustomersToManageSubscriptions;
   model.HideReturnRequests = !_orderSettings.ReturnRequestsEnabled || _orderService.SearchReturnRequests(customer.Id, 0, null).Count == 0;
   model.HideDownloadableProducts = _customerSettings.HideDownloadableProductsTab;
   model.HideBackInStockSubscriptions = _customerSettings.HideBackInStockSubscriptionsTab;
   return model;
}

CustomerNavigationModel.cs:

public partial class CustomerNavigationModel : BaseNopModel
{
    public bool HideInfo { get; set; }
    public bool HideAddresses { get; set; }
    public bool HideOrders { get; set; }
    public bool HideBackInStockSubscriptions { get; set; }
    public bool HideReturnRequests { get; set; }
    public bool HideDownloadableProducts { get; set; }
    public bool HideRewardPoints { get; set; }
    public bool HideChangePassword { get; set; }
    public bool HideAvatar { get; set; }
    public bool HideForumSubscriptions { get; set; }

    public CustomerNavigationEnum SelectedTab { get; set; }
 }

public enum CustomerNavigationEnum
{
    Info,
    Addresses,
    Orders,
    BackInStockSubscriptions,
    ReturnRequests,
    DownloadableProducts,
    RewardPoints,
    ChangePassword,
    Avatar,
    ForumSubscriptions
}

MyAccountNavigation.cshtmlスニペット:

 @model CustomerNavigationModel
 @using Nop.Web.Models.Customer;
 @if (!Model.HideInfo)
 {
      <li><a href="@Url.RouteUrl("CustomerInfo")" class="@if (Model.SelectedTab == CustomerNavigationEnum.Info)
          {<text>active</text>}
          else
          {<text>inactive</text>}">@T("Account.CustomerInfo")</a></li>}

ビュー:@ Html.Partial( "MyAccountNavigation"、Model.NavigationModel、new ViewDataDictionary())

MyAccountNavigationはコントローラーに存在しないため、レンダリングできないことを認識しています。ただし、構文が配置されているページによっては機能します。では、コントローラーのコードを変更せずにそれを実現する方法はありますか?前もって感謝します。

4

2 に答える 2

0

あなたの質問から私が理解していることは、多くのページから「MyAccountNavigation」部分ビューを実行する必要があり、そのためにこの部分ビューを共有フォルダーに配置できるということです。

間違っている場合は修正してください。

編集されたテキスト

ベースコントローラー:

ExcecuteCore メソッド

メニューまたはそのモデルを ViewBag のように保存できます

var customerNavigationModel = assigned your value;
ViewBag.MenuData = customerNavigationModel;

ビューから

@{Html.RenderPartial("MyAccountNavigation", ViewBag.MenuData);}
于 2012-09-10T10:32:05.110 に答える
0

MVC は特定の順序で部分ビューを探します。MyAccountNavigation.cshtml' into部分ビューを機能させるには、 ~/Views/Shared/`を配置する必要があります

私はソースを見てきましたが、これは何が起こるかです:

 public RazorViewEngine(IViewPageActivator viewPageActivator)
            : base(viewPageActivator)
        {
            AreaViewLocationFormats = new[]
            {
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/{1}/{0}.vbhtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.vbhtml"
            };
            AreaMasterLocationFormats = new[]
            {
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/{1}/{0}.vbhtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.vbhtml"
            };
            AreaPartialViewLocationFormats = new[]
            {
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/{1}/{0}.vbhtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.vbhtml"
            };

            ViewLocationFormats = new[]
            {
                "~/Views/{1}/{0}.cshtml",
                "~/Views/{1}/{0}.vbhtml",
                "~/Views/Shared/{0}.cshtml",
                "~/Views/Shared/{0}.vbhtml"
            };
            MasterLocationFormats = new[]
            {
                "~/Views/{1}/{0}.cshtml",
                "~/Views/{1}/{0}.vbhtml",
                "~/Views/Shared/{0}.cshtml",
                "~/Views/Shared/{0}.vbhtml"
            };
            PartialViewLocationFormats = new[]
            {
                "~/Views/{1}/{0}.cshtml",
                "~/Views/{1}/{0}.vbhtml",
                "~/Views/Shared/{0}.cshtml",
                "~/Views/Shared/{0}.vbhtml"
            };

            FileExtensions = new[]
            {
                "cshtml",
                "vbhtml",
            };
        }

と に興味がAreaPartialViewLocationFormatsありPartialViewLocationFormatsます。

これは、顧客関連のビュー内でビューを使用しようとするとビューが検出され、それ以外の場所では機能しない理由を説明しています。

于 2012-09-11T07:59:34.690 に答える