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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naresh Kumar KattaRank #1,104 · 1.7K reputationPosted Nov 25, 2025, 12:11 PM EST
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!
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 26, 2025, 10:47 PM EST
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.cshtml