4
Well, I’m trying to perform a consultation on Dapper
and get the following error:
The model item inserted in the dictionary is of type'System.Collections.Generic.List`1[Taxability Fertility.Models.Parents]', but this dictionary requires an item of type 'Taxability Fertility.Models.Parents.'.
My entity Pais
is like this:
[Table("Pais")]
public class Pais
{
[Key]
public Guid PaisId { get; set; }
[Required]
public String Nome { get; set; }
public virtual ICollection<FertilidadePorAno> FertilidadePorAno { get; set; }
}
Controller:
public async Task<ActionResult> Relatorio(Guid id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var entries = db.Database.Connection.Query<Pais>(@"SELECT * from Pais where PaisId = @id", new { id = id});
return View(entries);
}
And my View:
@model TaxaDeFertilidade.Models.Pais
@{
ViewBag.Title = "Relatorio";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Relatorio</h2>
<div>
<h4>Pais</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Nome)
</dt>
<dd>
@Html.DisplayFor(model => model.Nome)
</dd>
</dl>
</div>
Threshing, I saw what object arrives filled in controller
But on the return of View
the problem happens. How do I solve it?
Your view asks for a
Pais
and you are sending a collection ofPais
– Jéf Bueno