I have two database table in one table district code is stored and district code is form another table, i want to fetch the value from database table and display in View
if dept = 1 then it will be like '3'
if dept = 2 then it will be like '4'
but in text.
Vishal JoshiPosted Dec 15, 2023, 11:40 AM
Hello
As per the secnario you need to write query on district master table. As you have district Id and based on that you can get district name from the master table and you can bind the district name along with district id in View Model.
once view model bind is done you can use the view model in aspx or cshtml page.
Please check the below sample query to get district name from district master table.
View model (i.e. cshtml page)
Thanks
Vishal Joshi
Anandu G NathPosted Dec 21, 2023, 5:58 AM
Hai
You can check my below code snippet that illustrates this concept in an ASP.NET MVC Controller:
Jayraj ChhayaPosted Dec 15, 2023, 11:23 AM
To fetch the district code from the database and display it in a view, you can follow these steps:
Retrieve the district code from the database based on the "dept" value using a query or an ORM (Object-Relational Mapping) framework like Entity Framework.
In your controller or view model, create a property to store the fetched district code.
By following these steps, you will be able to fetch the district code from the database and display it in the desired text format in your view based on the value of the "dept" field.