NickName:Mana Ask DateTime:2022-03-25T15:36:21 How to display name instead of id in ASP.NET Core? im using visual studio with asp.net core.My database is MSSQL. Im following tutorial from youtube. Currently i ran a problem where it display the id instead of name. Here is the picture of what i try to create/add Here is the picture of my problem Since i dont know what code to include i just give my github link [text] Copyright Notice:Content Author:「Mana」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.Link to original article:https://stackoverflow.com/questions/71613506/how-to-display-name-instead-of-id-in-asp-net-core Answers Xinran Shen 2022-03-28T03:22:52 the type of model.COURT_TYPE is int, so the page display 1 is no problem, But your prupose is display the dropdownlist's text not the value, So you can use linq to select in viewbag.\nI write a simple demo here.\n //Here the Id is your COUNT_TYPE, in your code, \n you use select from db to get the COUNT_TYPE, \n For testing convenience, I just hard code here to get the \n data from other action.\n\n //In your code, You save the value and text of the dropdownlist in the database, \n I just hard code here and use `items` of type List<T> to include them.\n\npublic IActionResult Privacy(int id)\n {\n\n List<SelectListItem> test = new List<SelectListItem>();\n\n foreach (var item1 in items)\n {\n test.Add(new SelectListItem { Text = item1.Name, Value = item1.Id.ToString() });\n }\n ViewBag.Items1 = test;\n\n\n Item item = new Item();\n item.Id = id;\n return View(item);\n }\n\npage\n@model ViewBagTest.Models.Item\n@{\n ViewData["Title"] = "Privacy Policy";\n var test = ((List<SelectListItem>)ViewBag.Items1).Where(x => x.Value == Model.Id.ToString()).Select(x=>x.Text).First();\n}\n<h1>@ViewData["Title"]</h1>\n<h1>@test</h1>\n\n", Manektech Knowledge Base 2022-03-25T09:27:50 As you said it is displaying ID instead of name because in your code, you are binding ID itself.\nIn your index view,\n <th>\n <i class="@sortModel.GetColumn("COURT_TYPE").SortIcon" arial- \n hidden="true"></i>\n\n <a asp-action="Index" asp-route- \n sortExpression="@sortModel.GetColumn("COURT_TYPE").SortExpression">\n @Html.DisplayNameFor(model => model.COURT_TYPE)\n </a>\n </th>\n\nyou can see above that you are binding model.Court_type.\nNow if you look at your model,\n //Cascade|Dropdown\n\n [ForeignKey("COURT_TYPE")]\n [Display(Name = "COURT_TYPE")]\n public int? COURT_TYPE { get; set; }\n public virtual COURT_TYPE Court_Types { get; set; }\n\nAs you can see Court_Type is INT so definitely it will display INT value. If you want to display name then you have get through Court_Types object.\nIn another way,\n public PaginatedList<LawReview> GetItems(string SortProperty, SortOrder sortOrder, string SearchText = "", int pageIndex = 1, int pageSize = 5)\n {\n List<LawReview> items;\n\n if (SearchText != "" && SearchText != null)\n {\n items = _context.LawReviews.Where(n => n.LAWREVIEW_ID.ToString().Contains(SearchText) || n.JUDGMENT_NAME.Contains(SearchText) || n.JUDGMENT_NAME_VERSUS.Contains(SearchText) || n.JUDGMENT_NAME_ADDITIONAL.Contains(SearchText) || n.Court_Types.Name.Contains(SearchText) || n.Judge_Names.Name.Contains(SearchText) || n.JUDGMENT_NUMBER.Contains(SearchText) || n.JUDGMENT_DATE.Contains(SearchText) || n.HEADNOTE.Contains(SearchText) || n.Judgment_Countries.Name.Contains(SearchText) || n.States.Name.Contains(SearchText) || n.Judgment_Languages.Name.Contains(SearchText) || n.Catchword_Lv1.Name_Lv1.Contains(SearchText) || n.Catchword_Lv2.Name_Lv2.Contains(SearchText) || n.Catchword_Lv3.Name_Lv3.Contains(SearchText) || n.Catchword_Lv4.Name_Lv4.Contains(SearchText) || n.VERDICT.Contains(SearchText))\n .Include(u => u.Court_Types)\n .ToList();\n }\n else\n items = _context.LawReviews\n .Include(u => u.Court_Types).Include(r => r.Judge_Names).Include(s => s.Judgment_Countries).Include(t => t.Judgment_Languages).Include(v => v.Catchword_Lv1).Include(w => w.Catchword_Lv2).Include(x => x.Catchword_Lv3).Include(y => y.Catchword_Lv4).Include(z => z.States)\n .ToList();\n\n items = DoSort(items, SortProperty, sortOrder);\n\n PaginatedList<LawReview> retItems = new PaginatedList<LawReview>(items, pageIndex, pageSize);\n\n return retItems;\n }\n\nHere in items, you can use select and get the name from courtType object which I believe would be in relation with your primary table.",