I am trying to pass anonymous type to view but It's get Error to find The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[<>f__AnonymousType1`2[System.Int32,System.Int32]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Test.Models.BidsDetails]'.
Where my model
public class BidsDetails
{
public int Id { get; set; }
public int BidsId { get; set; }
public int ProductId { get; set; }
public int BidsPrice { get; set; }
public virtual Bids Bids { get; set; }
public virtual Product Product { get; set; }
}
my Controller
[HttpGet]
public ActionResult Winner()
{
TestDbContext db = new TestDbContext();
var result = db.bidsDetails
.GroupBy(g => g.ProductId)
.Select(s => new
{
productId = s.Key,
BidsPrice = s.Max(m => m.BidsPrice)
}).ToList();
return View(result);
}
My view
@model IEnumerable<Test.Models.BidsDetails>
@{
ViewBag.Title = "Winner";
}
<h2>Winner</h2>
<table class="table">
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Bids.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Product.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.BidsPrice)
</td>
</tr>
}
</table>
I am beginner to asp.net MVC
.
So, How to solve this problem ?