Need some help with fixing values that are extracting in from DB via ViewBag dropdown binding.
Results are coming as whiteout, which means data is not visible in View.
Here is my Code
Class
[Key]
public int countryId { get; set; }
public IEnumerable<SelectList> countryName { get; set; }
public string countryCode { get; set; }
Controller
public ActionResult DropDown()
{
using (Db db = new Db())
{
ViewBag.countryVal = new SelectList(db.Countries.ToList(), "countryName", "countryName");
return View();
}
}
View
<table>
<tbody>
<td>
@Html.DropDownList("countryVal", "Select")
</td>
</tbody>
</table>
Screenshot
Any help is very much appreciated.
Thanks
Your countryName filed is invalid. You need to make it as string countryName as follows.
Country
Your controller look like below:
Now in UI need some changes as per below: