【发布时间】:2015-12-19 07:26:20
【问题描述】:
运行我的 mvc 应用程序时出现以下错误:
{"The model item passed into the dictionary is of type
'System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`
1[PM.CManager.Clm.Domain.Models.Ln]]', b
ut this dictionary requires a model item of type 'PM.CManager.Clm.Domain.Models.Ln'."}
下面是我的控制器返回值:
public ActionResult ClaimDetail()
{
//return View();
string id = "1000000246";
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var LnDetail = _LnProxy.GetLnDetailByLnNum((string)id);
if (LnDetail == null)
{
return HttpNotFound();
}
return View(LnDetail);
}
以下是我的看法:
@model PM.CManager.Clm.Domain.Models.Ln
@using (Html.BeginForm())
{
<div class="panel panel-primary">
<div class="panel-heading inform" style="">
<table clases="panel-title inform">
<tr>
<td class="inform">Ln Number: <label id="Lnnum" name="Lnnum">1000100001</label></td>
<td class="inform">Status: <label id="Lnstatus" name="Lnstatus">Forclosure</label></td>
<td class="inform">Ln Type: <label id="Lntype" name="Lntype">Government(FHA)</label></td>
</tr>
</table>
</div>
为了解决这个问题,需要对下面的行做哪些更改?
@model PM.CManager.Clm.Domain.Models.Ln
【问题讨论】:
-
_LnProxy.GetLnDetailByLnNum((string)id)返回什么?您需要在您的视图中完全匹配。 -
首先,您需要等待 _LnProxy.GetLnDetailByLnNum((string)id) 返回的内容,因为它是一个任务。其次,您的视图需要单个项目,但该函数返回一个集合。在这种情况下,我们无能为力。
标签: c# .net model-view-controller task-parallel-library