MVC Razor DropDownList not populating value, system.data.datarow instead
I am diving into MVC and hit a snag.
In my home controller I am populating a ViewBag. Then I am trying to put that into a drop down list
Home controller:
string _connectionString = WebConfigurationManager.ConnectionStrings["xxxxxxx"].ToString(); using (SqlConnection con = new SqlConnection(_connectionString)) { // // Open the SqlConnection. // con.Open(); // // The following code uses an SqlCommand based on the SqlConnection. // SqlDataAdapter _da = new SqlDataAdapter("Select Name from AspNetRoles", con); DataTable _dt = new DataTable(); _da.Fill(_dt); ViewBag.RoleList = new SelectList(_dt.AsEnumerable()); con.Close(); }
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst