Reputation: 1269
Model:
public class TestModel
{
[Column]
public string Name { get; set; }
}
Controller:
TestModel[] metadata = context.GetTable<TestModel>().ToArray();
return View(itemsToShow.ToList());
the name column and sorts it alphabethically on user selection which works fine (have tested it in debug mode - for example if user selects 'd' it only will display the items starting with 'd'.)
The problem is when i add "@model IEnumerable" and foreach loop in the view I get the error.
Upvotes: 1
Views: 1957
Reputation: 3812
Why you call .ToList()
on your itemsToShow
? (i think it is only a duplication)
Change List<string> items
to IEnumerable<string> items
and remove .ToList()
from last line
Upvotes: 0
Reputation: 125488
The problem is your view is expecting a type of IEnumerable<TestModel>
for the model but you are passing in IList<String>
as the error message indicates.
It looks like you shouldn't be projecting metadata
to an IList<String>
in your controller and passing to the view but instead should be filtering metadata
like
IEnumerable<TestModel> metadata = context.GetTable<TestModel>().ToArray();
var itemsToShow = string.IsNullOrEmpty (page)
? metadata
: metadata.Where(x => x.Name.StartsWith(page, true, null));
ViewData["currentPage"] = page ?? string.Empty;
return View(itemsToShow.ToList());
Upvotes: 1