传递到字典中的模型项的类型为'System.Threading.Tasks.Task`1 [System.Collections.Generic.IEnumerable`

Sma*_*EGA 4 .net c# model-view-controller task-parallel-library

运行我的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'."}
Run Code Online (Sandbox Code Playgroud)

以下是我的控制器返回值:

 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);
        }
Run Code Online (Sandbox Code Playgroud)

以下是我的观点:

@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>
Run Code Online (Sandbox Code Playgroud)

对于下线来解决此问题可能需要做哪些更改?

@model PM.CManager.Clm.Domain.Models.Ln
Run Code Online (Sandbox Code Playgroud)

jan*_*ann 9

看起来你正在返回这一行的Task表单:

var LnDetail = _LnProxy.GetLnDetailByLnNum((string)id);
Run Code Online (Sandbox Code Playgroud)

这需要改为:

var LnDetail = await _LnProxy.GetLnDetailByLnNum((string)id);
Run Code Online (Sandbox Code Playgroud)

然后,您需要将方法的签名更改为:

public async Task<ActionResult> ClaimDetail() { /* ... */ }
Run Code Online (Sandbox Code Playgroud)

另外请记住,如果它是一个集合或单个项目,并相应地调整您的视图.

  • 是的,这是因为它正在回归你的收藏品.将您的视图更改为"@model IList <PM.CManager.Clm.Domain.Models.Ln>" (2认同)