OwnurD
OwnurD

Reputation: 195

The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Objt

The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Donemler_8A34F5A0E6AB4F6429B22B8E4A5B0CDD80C5DCEA6C183E8068EDB99DF7FA8263', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Anket.Data.DomainModel.Donemler]'.

Here is my code:

Controller part

public ActionResult _DonemGetir(int id)
    {
        var donem = donemService.Bul(id);
        return PartialView(donem);
    }

Service Class

public Donemler Bul(int id)
    {
        return db.Donem.Find(id);
    }

View Part

    @model IEnumerable<Anket.Data.DomainModel.Donemler>
    @{
          foreach (var item in Model)
          {
           @Html.DisplayFor(model => item.donem )
          }
     }

Id value in Controller( _DonemGetir(int id) ) comes from another view and those View Codes :

@model IEnumerable<Anket.Data.DomainModel.Anketler>


 @foreach(var item in Model)
 {
 <tr>


     <td class="nameRecord">
         @Html.Action("_DonemGetir", "Ortak", new { id = item.ID })
     </td>

 </tr>
 }
</table>

_DonemGetir View :

@model IEnumerable<Anket.Data.DomainModel.Donemler>


@{
  foreach (var item in Model)
  {
    @Html.DisplayFor(model => item.donem )
  }
}

I have two tables:

Anketler and Donemler

Anketler table has :

ID(PK) - name - and donem_id (FK)

Donemler table has :

ID(PK) - name

I want to fetch data from Anketler and I do not want to fetch donem_id as an integer. I need it's name from Donemler table. I tried to do this with these codes.

Upvotes: 1

Views: 2298

Answers (1)

OwnurD
OwnurD

Reputation: 195

I fixed the problem

I changed _DonemGetir View like this

@model  Anket.Data.DomainModel.Donemler

@{

@Html.DisplayFor(model => model.donem)  

}

Upvotes: 0

Related Questions