Mona Coder Mona Coder - 1 year ago 62
C# Question

Issue on Populating Data on Drop-down List in ASP.Net MVC

I am trying to Load data from

table into a Bootstrap Drop down list like:

<div class="form-group">
<label for="sel1"></label>
<select class="form-control" id="cat">
<option>Select From The List</option>
DataEntities ctx = new DataEntities();
var cat = ctx.Categories.OrderByDescending(p => p.CategoryName);
foreach (var item in cat)

but I am getting this is result

enter image description here

the count of
is equal to number of rows in
table but I am not getting the actual value! . Can you please let me know what i am doing wrong?

Answer Source

You're missing an @ symbol in your option tag.

foreach (var item in cat)

In your code, you're just adding the string "item" for each item in cat.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download