razor - Render data from database in layout file -


i want include data (fetching database) in _layout file of asp.net mvc core project.

situation:

_layout page

@if (signinmanager.issignedin(user)) {    html.action("modules", "layout") } 

controllers/layoutcontroller.cs

using microsoft.aspnetcore.mvc;  namespace project.controllers {    public class layoutcontroller : controller    {        ...         public actionresult modules()        {            ///return modules            return partialview("_modules", moduleaccess.tolist());        }    } } 

views/shared/_modules.cshtml

@model ienumerable<project.models.module> <div class="two wide column"> <div class="ui menu" id="modules">     @foreach (var item in model)     {         <a class="item">             @html.displayfor(modelitem => item.name)         </a>     } </div> 

when going webpage following error:

'ihtmlhelper<dynamic>' not contain definition 'action' , best extension method overload 'urlhelperextensions.action(iurlhelper, string, object)' requires receiver of type 'iurlhelper' 

what doing wrong? how can data in layout page?

in asp.net core instead of html.action use view components: @await component.invoceasync.

you can still use @await html.renderpariantasync , pass there data model if want.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -