I have got one question, how can I get category name in details.cshtml by foreign key – CategoryId in work model?
work.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace InfoKiosk.Domain.Entities
{
public class Work
{
public int WorkId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int CategoryId { get; set; }
public Category Category { get; set; }
}
}
category.cs
public class Category
{
public int CategoryId { get; set; }
public string Name { get; set; }
}
The names of categories I choose from dropdownlist which one I populate from ViewBag.
details.cshtml
<dt>
<strong>@Html.DisplayNameFor(model => model.Category):</strong> @Html.DisplayFor(model => model.???)
</dt>
2
Answers
You can pass this in a
ViewBag
to the the view maybe fromController
:use this
in your action include category