vishnu sharma

vishnu sharma

  • NA
  • 18
  • 847

getting selected Id instead of Name from dropdown

Jul 26 2018 3:00 AM
public partial class EntryTable
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public long Mobile { get; set; }
public string Email { get; set; }
[Display(Name="City")]
public int CityId { get; set; }
public IEnumerable<SelectListItem> City { get; set; }
[Display(Name="Category")]
public int CategoryId { get; set; }
public IEnumerable<SelectListItem> Category { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
}
 
//controller 
 
public ActionResult Index()
{
return View(db.EntryTables.ToList());
}
 
//View
 
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.CityId)
</th>
<th>
@Html.DisplayNameFor(model => model.CategoryId)
</th>
<th>
 
here i created two dropdowns, one for City and another for Category. My table is showing only Id of selected dropdown istead of Name.
how can i show the name from selected dropdown in the index view table. 

Answers (4)