物品有关系吗?如果是,则考虑创建一个 ViewModel,它是每个模型的聚合:
public CustomerViewModel
{
public Customer Customer {get; set;
public AddressViewModel Address {get; set;}
public OrderViewModel Order {get; set;}
}
那么在你看来:
@inherits System.Web.Mvc.WebViewPage<CustomerViewModel>
@model CustomerViewModel
@Model.Customer.Name
@Model.Address.Street
@Model.Order.Name
@model.Order.Date
否则,如果这些项目根本不相关,那么您可以使用RenderAction
:
在您Customer
看来:
@Model.Customer.Name
@(Html.RenderAction("GetAddress", "Customer", new { customerId = Model.Customer.Id });)
@(Html.RenderAction("GetOrders", "Order", new { customerId = Model.Customer.Id });)