我不知道如何最好地描述我的要求,但这里有。我正在尝试在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 因为它在控制器中不存在。但是,取决于放置语法的页面,它会起作用。那么有没有办法在不更改控制器中的代码的情况下实现这一点?提前致谢。