Error rendering PartialView in a View

0

I have a View and inside it I want to render a PartialView . What happens is that the partial is of a different model , but that has a relationship between them.

I want to show a partial as if it were index , where I show everything that is related to Id by passing Url to action . This action that receives the Id is the action of details, because it shows the data all. And within that detail , show that partial that relates to the last Id.

I had done this before on another project. So I decided to follow the same steps to do it again, but it is not working.

When rendering View , an error is already shown:

  An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code   Additional information: The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.AccAvaliacaoComposic_2033E49B3B44E5935B12E9A68FD75A0C5C81F4AB3E35937D92A1C78CB15ACE30', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable'1 [MyProject.Models.AccApplicationCorporal ] '.

And I do not know how to do it anymore, because everything I saw is right.

The way I call this partial is: inside the controller RetRetorno , I have a actionresult which is called PartialAcc , which is used to fetch the data related to the id passed in the url of the action of details. I tried everything, but it did not work.

The codes I have are:

Action Details

 // GET: RetRetorno/Details/5
    public ActionResult Details(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }

        //RetRetorno retRetorno = db.RetRetorno.Find(id);

        RetRetorno retRetorno = db.RetRetorno.Include(o => o.AccAvaliacaoComposicaoCorporal).
            Include(p => p.CliCliente).AsNoTracking().FirstOrDefault(f => f.RetId == id);

        if (retRetorno == null)
        {
            return HttpNotFound();
        }

        return View(retRetorno);
    }

Action I use to call partial

   public ActionResult PartialAcc(int? id)
    {
        //AccAvaliacaoComposicaoCorporal acc = db.AccAvaliacaoComposicaoCorporal.Include(o => o.CliCliente).AsNoTracking().ToList().FirstOrDefault();

        //return View(db.AccAvaliacaoComposicaoCorporal.Include(o => o.CliCliente).AsNoTracking().ToList().FirstOrDefault());

        var acc = db.AccAvaliacaoComposicaoCorporal.AsEnumerable();

        return View(acc);

    }

Na view details

...

<h2>Details</h2>

<div>
<h4>RetRetorno</h4>
<hr />

@Html.Partial("PartialAcc", Model.AccAvaliacaoComposicaoCorporal)

...

The partial I call is like the index itself, but I'll put the codes here:

@model IEnumerable<MeuProjeto.Models.AccAvaliacaoComposicaoCorporal>

<table class="table table-striped">
    <tr>
        <th>
            @*@Html.DisplayNameFor(model => model.AccPeso)*@
            Peso
        </th>
        <th>
            @*@Html.DisplayNameFor(model =>

...

What am I doing wrong?

    
asked by anonymous 19.06.2016 / 00:55

1 answer

0

You're passing this:

@model MeuProjeto.Models.AccAvaliacaoComposicaoCorporal

Your Partial asks this:

@model IEnumerable<MeuProjeto.Models.AccAvaliacaoComposicaoCorporal>

Change @model to a simple object (not IEnumerable ) that should work.

It will look like this:

@model MeuProjeto.Models.AccAvaliacaoComposicaoCorporal

<table class="table table-striped">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.AccPeso)
            Peso
        </th>
        <th>
            @Html.DisplayNameFor(model => ...
    
19.06.2016 / 02:07