my application is asp.net MVC3 using Entity Framework. I am trying to get a list of one column from a table as an array using the following:
public ActionResult Index()
{
//var list = db.CasesProgresses.ToList();
var SeriesList = GetSeriesList(Learner_ID);
return View();
}
public List<string> GetSeriesList(string item)
{
// get DataTable dt from somewhere.
List<string> sList = new List<string>();
foreach (CasesProgress row in db.CasesProgresses)
{
sList.Add(row[0].ToString());
}
return sList;
}
I get two errors:
Cannot apply indexing with [] to an expression of type 'caseprog.Models.CasesProgress' and
The name 'Learner_ID' does not exist in the current context
Would appreciate your suggestions.
if you are using a foreach, there is no
[0]. If you were using a normalfor (int i =0; i < list.Count; i ++;)then you would be able to do that. But then ofcourse you would have to change the0toi, and you would still need to access a property. Well you wouldn’t have to do that if your List had a different type, but in your current example you will need to add a String.