I'm able to return the CategoryName field into a list via ViewBag.Categories. I also want to return the CategoryId field and use it to dynamically build the category Details view URL
This is the controller action:
public ActionResult Details(Item item)
{
var db = new appContext();
ViewBag.Item = item.ItemTitle;
ViewBag.ItemLink = "http://localhost:4444/Items/Details/" + item.ItemId;
ViewBag.Categories = new List<string>(item.Categories.Select(c => c.CategoryName));
return View();
}
This is the view where the list of categories is returned:
@foreach (string category in ViewBag.Categories)
{
<li>
<a href="http://localhost:4444/Categories/Details/???">@category</a>
</li>
}
How can I return CategoryIdas shown above?