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

时间:2015-09-22 10:43:33

标签: c# .net 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'."}

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

 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

1 个答案:

答案 0 :(得分:9)

您似乎正在返回此行的任务表单:

<servlet>
    <servlet-name>WebService</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.example.demo.webservice</param-value>
        //Package
    </init-param>
    <init-param>
        <param-name>unit:WidgetPU</param-name>
        <param-value>persistence/widget</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>WebService</servlet-name>
    <url-pattern>/webservices/*</url-pattern>
</servlet-mapping>

这需要更改为:

var LnDetail = _LnProxy.GetLnDetailByLnNum((string)id);

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

var LnDetail = await _LnProxy.GetLnDetailByLnNum((string)id);

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