Hi ,
can anyone suggest with sample code to bind fmenu from myslq db in _Layout.cshtml . ?
sample code is vital for implement.
Thanks in advance
Karthik.k
Hi ,
can anyone suggest with sample code to bind fmenu from myslq db in _Layout.cshtml . ?
sample code is vital for implement.
Thanks in advance
Karthik.k
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Nov 27, 2025, 3:47 AM
Hello Karthik,
I think you have SQM table ready so sharing only MVC code example here,
Step 1: Create model for you table to map data
Step-2 : Create service to Fetch data from database
Step-3: Register service in program file.
step-4 : Create viewComponent
STEP 5 Create View for the Component
STEP 6 Call Component Inside
_Layout.cshtmlNaresh Kumar KattaPosted Nov 25, 2025, 5:11 PM
Hi Karthik,
Here's a practical approach to bind menu data from MySQL in your _Layout.cshtml using ASP.NET Core with Entity Framework:
Step 1: Create a ViewComponent
First, create a ViewComponent to fetch the menu data:
Step 2: Create the ViewComponent View
Create
Views/Shared/Components/Menu/Default.cshtml:Step 3: Invoke in _Layout.cshtml
This approach keeps your layout clean and separates concerns. The ViewComponent handles the database logic, and the view renders the menu.
Let me know if you need clarification on any part!