Load one tab into another

Asked

Viewed 49 times

0

I have a layout page where I want to upload information to the notifications button.

For this, I made an action in the controller to return a Partialview where a query will be made in the bd looking for the information.

How do I load this page into the layout so that it goes through the action and loads the information?

public IActionResult Notificacoes()
        {
            var pessoa = (from p in _context.ApplicationUsers where p.Id == _userManager.GetUserId(User) select p).SingleOrDefault();
            var notificacoes = _context.PublicacaoAmigos.Include(m => m.Pessoa).Where(n => n.Status != "Visto").Where(n => n.Amigo == pessoa);
            return PartialView("Notificacoes", notificacoes);
        }

html publishing.

@foreach (var item in Model) {

<li>
      <div class="media-body">
          <strong class="notification-title"> @Html.DisplayFor(modelItem => item.Pessoa.Nome) @Html.DisplayFor(modelItem => item.Pessoa.Sobrenome) marcou você </strong>
          <p class="notification-desc">em uma publicação</p>
            @Html.ActionLink("Ver Publicação", "Publicacoes", "Materiais", new{id = item.Pessoa.Id })
          <div class="notification-meta">
            <small class="timestamp">@Html.DisplayFor(modelItem => item.Data)</small>
          </div>
        </div>
    </li>
    }

html layout.

 <ul class="dropdown-menu" id="lista_notificacoes">

   @await Html.PartialAsync("Publicacoes")

    </ul>
  • You get some mistake ?

  • An error in my foreach @foreach (var item in Model) because apparently you are not going through the action: Nullreferenceexception: Object Reference not set to an instance of an Object.

  • Have you tried using Renderaction() ?

  • Yes, it seems that Renderaction() has been replaced by Viewcomponent but I don’t know how to use: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.1

  • @await Component.InvokeAsync("Publicacoes")

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.