튜플을 사용하여 한 뷰에서 두 모델을 사용하려고하지만이 오류가 발생합니다. '/'응용 프로그램의 서버 오류입니다.ASP.NET MVC 4에서 튜플을 올바르게 사용하는 방법
The model item passed into the dictionary is of type 'PagedList.PagedList
1[S00117372CA3.Product]', but this dictionary requires a model item of type 'System.Tuple
2[PagedList.IPagedList1[S00117372CA3.Product],System.Collections.Generic.IEnumerable
1[S00117372CA3.Order]]'.
설명 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 오류 및 코드에서 시작된 위치에 대한 자세한 정보는 스택 추적을 검토하십시오.
@*@model PagedList.IPagedList<S00117372CA3.Product>*@
@model Tuple<PagedList.IPagedList<S00117372CA3.Product>, IEnumerable<S00117372CA3.Order>>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Item1[0].ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].Supplier.CompanyName)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].Category.CategoryName)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].QuantityPerUnit)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].UnitPrice)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].UnitsInStock)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].UnitsOnOrder)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].ReorderLevel)
</th>
<th>
@Html.DisplayNameFor(model => model.Item1[0].Discontinued)
</th>
<th></th>
</tr>
@foreach (var item in Model.Item1) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Supplier.CompanyName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Category.CategoryName)
</td>
<td>
@Html.DisplayFor(modelItem => item.QuantityPerUnit)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitPrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitsInStock)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitsOnOrder)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReorderLevel)
</td>
<td>
@Html.DisplayFor(modelItem => item.Discontinued)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ProductID }) |
@Html.ActionLink("Details", "Details", new { id=item.ProductID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ProductID })
</td>
</tr>
}
</table>
<div>
Page @(Model.Item1.PageCount < Model.Item1.PageNumber ? 0 : Model.Item1.PageNumber) of @Model.Item1.PageCount
@if (Model.Item1.HasPreviousPage)
{
@Html.ActionLink("<<", "Index", new { page = 1})
@Html.Raw(" ");
@Html.ActionLink("< Prev", "Index", new {page = Model.Item1.PageNumber - 1})
}
else{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.Item1.HasNextPage)
{
@Html.ActionLink("Next >", "Index", new {page = Model.Item1.PageNumber + 1})
@Html.Raw(" ");
@Html.ActionLink(">>", "Index", new {page = Model.Item1.PageCount})
}
else{
@:Next >
@Html.Raw(" ")
@:>>
}
</div>
@foreach (var item in Model.Item2)
{
@Html.Partial("_Orders")
}
여기의 요청에 따라 내 컨트롤러 코드 :
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'PagedList.PagedList
1[S00117372CA3.Product]', but this dictionary requires a model item of type 'System.Tuple
2[PagedList.IPagedList1[S00117372CA3.Product],System.Collections.Generic.IEnumerable
1[S00117372CA3.Order]]'.
여기 내 코드는 기본적으로
var q = (from o in db.Order_Details
where o.ProductID == id
join ord in db.Orders
on o.OrderID equals ord.OrderID
orderby o.Quantity descending
select ord);
var qm = q.Take(3);
return PartialView("_Orders", qm.ToList());
가 왜'Tuple'를 사용
뷰는 현재 뷰 모델에 강력한 입력 할 수 있습니다? 둘러싸는 클래스의 양쪽 모두의 오브젝트를 랩합니다. 그것은 훨씬 더 좋네 .. 그리고 모델 바인더와도 작동합니다. –
나는 그 일을하는 법을 모르기 때문에. 환상적인 예와 링크를 게시 할 수 있다면. 감사합니다 –
문제는 컨트롤러에서 잘못된 데이터 형식을보기로 전달하고 있다는 것입니다. 귀하의 컨트롤러 코드는 무엇입니까? –