NVO
NVO

Reputation: 2703

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

I have looking on SO but I didn't find a solution and I'm totally lost the correct way to fix this.

What's happening? I'm getting error CS0411 in a view: the type arguments for method cannot be inferred from the usage mvc I'm using a Tuple in that view to use 2 models.

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

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

And I want to use the field TicketQuantity.

@Html.HiddenFor(item.TicketQuantity)

But that's give the error. I can use the property in the view without any @Html functions.

The views:

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; }
}

Upvotes: 2

Views: 2827

Answers (1)

Rik
Rik

Reputation: 29243

I'm assuming for the moment you're looping through an IEnumerable like this:

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

The HiddenFor method takes a delegate as an argument, so instead of this:

@Html.HiddenFor(item.TicketQuantity)

you need to do something like this:

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

Upvotes: 1

Related Questions