Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

There is no argument given that corresponds to the required formal parameter - Why?

$
0
0

It's like I'm trying to get my menu controller to show the menus I've added in the database to see if they should be displayed or not.

but if, for example, I just get content, then I will not get the content.

Menu.cshtml.cs

public List<ContentInfo> GetListMenu { get; set; }


        private readonly DBContext _dbContext;

        public MenuModel(DBContext context)
        {
            _dbContext = context;
        }


        public void OnGet()
        {
            GetListMenu = _dbContext.ContentInfo.Where(i => i.ShowMenu == true).OrderByDescending(i => i.Id).ToList();
        }

It's my menu model file that I need to use over to my _layout.cshtml file.

_Layout.cshtml here:

@{
    var menuModel = new NewWebsite_Site_2018.Pages.View.ViewBar_Info.MenuModel();
}

.....

@Html.Partial("View/ViewBar_Info/Menu.cshtml", menuModel.GetListMenu)

and my Menu.cshtml file: 

@page
@model NewWebsite_Site_2018.Pages.View.ViewBar_Info.MenuModel

@foreach (var item in Model.GetListMenu)
{
    <a>@item.Name</a>
}

Question is so how can I get my menu to appear?

Error: There is no argument given that corresponds to the required formal parameter 'context' of 'MenuModel.MenuModel(DBContext)'


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>