我正在尝试使用mvc razor显示数据库中的数据,但我无法这样做。 这是我的代码
我正在尝试以twine id显示总价格。但没有任何表现。 可能的原因是什么?
查看
@model CustomerRevenueModel
@using Nop.Web.Models.Customer
<div class="tab-body revenue">
@foreach (var revenue in Model.DesignWiseSplits)
{
<ul class="info">
<li> Twine:<span class="order-status ">@revenue.Twine</span></li>
<li>Designer Share:<span class="order-date">@revenue.DesignerShare.ToString()</span></li>
<li>Total:<span class="order-total">@revenue.Total</span></li>
</ul>
}
控制器
model.CustomerRevenueModel = PrepareCustomerRevenueModel();
[NonAction]
protected virtual CustomerRevenueModel PrepareCustomerRevenueModel()
{
var model = new CustomerRevenueModel();
model.DesignWiseSplits = _orderService.DesignWiseSplits(_workContext.CurrentCustomer.Id);
return model;
}
模型
namespace Nop.Web.Models.Customer
{
public partial class CustomerRevenueModel : BaseNopModel
{
public IList<DesignWiseTotal> DesignWiseSplits { get; set; }
public IList<Nop.Web.Models.Order.OrderDetailsModel.OrderItemModel> AllDesignerOrderItems { get; set; }
public int TotalRevenue { get; set; }
}
}
namespace Nop.Services.Orders
{
public class DesignWiseTotal
{
public decimal Total { get; set; }
public decimal DesignerShare { get; set; }
public Twine Twine { get; set; }
}
}
服务
public virtual IList<DesignWiseTotal> DesignWiseSplits(int customerId)
{
var query = _orderItemRepository.Table;
return query.Where(oi => oi.Product.Designer_Id == customerId)
.GroupBy(oi => oi.Product.Twine)
.Select(oi => new DesignWiseTotal
{
Total = oi.Sum(x => x.PriceExclTax),
Twine = oi.Key
}).ToList();
}
答案 0 :(得分:0)
看起来您没有从控制器操作将模型返回到视图。你的行为应该是这样的。确保您的视图的命名与您的操作相同,或在View()方法中指定它
public ActionResult PrepareCustomerRevenueModel()
{
var model = new CustomerRevenueModel();
model.DesignWiseSplits = _orderService.DesignWiseSplits(_workContext.CurrentCustomer.Id);
return View(model);
}
答案 1 :(得分:0)
而不是使用<li> Twine:<span class="order-status ">@revenue.Twine</span></li>
使用<li> Twine:<span class="order-status ">revenue.Twine</span></li>
将@revenue更改为收入