CS0411:无法从用法 mvc 中推断出方法的类型参数

CS0411: the type arguments for method cannot be inferred from the usage mvc

我一直在寻找 SO 但我没有找到解决方案,我完全失去了解决这个问题的正确方法。

发生了什么事? 我在视图中收到错误 CS0411:无法从用法 mvc 推断方法的类型参数 我在该视图中使用元组来使用 2 个模型。

var model = new Tuple<IList<TimeTableInsertModel>, List<Ticket>>(ttc.getTimeTableDetails(id), ticket);

@model Tuple<IList<TimeTableInsertModel>, List<Ticket>>

并且我想使用字段 TicketQuantity。

@Html.HiddenFor(item.TicketQuantity)

但这就是错误。我可以在视图中使用 属性 而无需任何 @Html 函数。

浏览量:

public class TimeTableInsertModel
{
    [Key]
    public int TimeTableId { get; set; }
    public int MovieId { get; set; }
    public int RoomId { get; set; }
    public int SeatsAvaible { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
    public virtual Movie Movie { get; set; }
    public virtual ICollection<Reservation> Reservations { get; set; }
    public virtual Room Room { get; set; }
    public int TicketQuantity { get; set; }
}


 public partial class Ticket
{
    public Ticket()
    {
        ReservationTickets = new HashSet<ReservationTicket>();
    }

    public int TicketId { get; set; }

    public string Name { get; set; }

    public decimal Price { get; set; }

    public virtual ICollection<ReservationTicket> ReservationTickets { get; set; }
}

我假设您正在像这样循环访问 IEnumerable:

@foreach (var item in Model.Item1)
{
    ...
    Html.HiddenFor(item.TicketQuantity);
    ...
}

HiddenFor 方法将一个委托作为参数,所以不是这样:

@Html.HiddenFor(item.TicketQuantity)

你需要做这样的事情:

@Html.HiddenFor( m = > item.TicketQuantity)