No meu layout tenho uma opção onde mostro algumas notificações, para isso incluir no layout uma partial :
@Html.Partial("_PartialNotificacoes")
@model IEnumerable<Generico.Dominio.TB_NOTIFICACAO>
@if (Model.Count() > 0)
{
foreach (var item in Model)
{
<a href="Home/LerNotificacao/@item.IDNOTIFICACAO">
<!--lista de notificações-->
<i class="fa fa-users text-aqua"></i> @Html.DisplayFor(c => item.DESCRICAO);
</a>
}
}
O problema ocorre quando e chamado uma nova página de listagem porque ela também vai ter o seu próprio IEnumerable, Exemplo de chamada da página:
public ActionResult ListarValorAssinatura()
{
var tbuscar = new ValorAssinaturaAplicacao();
var listar = tbuscar.ListarTodos();
var tbuscarNotificacao = new NotificacaoApliacao();
var retorno = tbuscarNotificacao.ListarTodos();
if (retorno != null)
{
ViewData["QtdNotificacao"] = retorno.Count();
// ViewData["ListaNotificacao"] = retorno;
}
return View(listar);
}
Neste ponto estou retornando a lista, mais não estou retornando as notificações, então tenho um erro:
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.Collections.Generic.List
1[Generico.Dominio.TB_VALOR_ASSINATURA]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[Generico.Dominio.TB_NOTIFICACAO]'.
Opções que já fiz teste:
@Html.Partial("_PartialNotificacoes")
@Html.Partial("~/BuscarNotificacoes/Home/_PartialNotificacoes.cshtml")
@Html.Action("BuscarNotificacoes", "Home").