Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The model item passed into the dictionary is of type 'System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`

I am getting the following error while running my mvc application :

{"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'."}

Below is my controller return value:

 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);
        }

Below is my view :

@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>

What is the possible change need to do for below line to fix this issue?

@model PM.CManager.Clm.Domain.Models.Ln
like image 965
SmartestVEGA Avatar asked Sep 22 '15 10:09

SmartestVEGA


1 Answers

It seems like you are returning a Task form this line:

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

This needs to be changed to:

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

Then you needs to change the signature of the method to:

public async Task<ActionResult> ClaimDetail() { /* ... */ }

Also bear in mind if its a collection or single item that comes though and adjust your view accordingly.

like image 73
janhartmann Avatar answered Sep 19 '22 10:09

janhartmann