在视图中使用多模型

Use Multi Model in View

请帮助我在 MVC 视图中使用两个模型。

底线我都用过了,还是不行:

@using HelpDesk.Models;

@model Tuple<IEnumerable<Ticket>, IEnumerable<Order_List>> 

这是我在红页中的错误:

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[HelpDesk.Models.Login]', but this dictionary requires a model item of type 'System.Tuple2[System.Collections.Generic.IEnumerable1[HelpDesk.Models.Ticket],System.Collections.Generic.IEnumerable1[HelpDesk.Models.Order_List]]'.

谢谢。

您可以创建一个包含这两个对象的新 ViewModel,而不是使用元组,就像一个容器。

像这样:

public class BothViewModel
{
    public IEnumerable<Order_List> Orders { get; set; }
    public IEnumerable<Ticket> Tickets { get; set; }
}

然后,在您的视图中,您可以使用新的 ViewModel(BothViewModel)

@model BothViewModel

希望这对您有所帮助。