in an ASP.NET MVC3 web application.
I have a view. the view has a IEnumerable model.
I need to loop through all the model's items and show the item.Name
The view:
@model IEnumerable<Object>
@{
ViewBag.Title = "Home";
}
@foreach (var item in Model)
{
<div class="itemName">@item.Name</div>
}
In the controller, I use Linq to entities to get the list of objects from the database.
The Controller:
public ActionResult Index()
{
IEnumerable<Object> AllPersons = GetAllPersons();
return View(AllSurveys);
}
public IEnumerable<Object> GetAllPersons()
{
var Context = new DataModel.PrototypeDBEntities();
var query = from p in Context.Persons
select new
{
id = p.PersonsId,
Name = p.Name,
CreatedDate = p.CreatedDate
};
return query.ToList();
}
When I run I get this error:
'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
How can I access the "Name" Property of the model items?
Thanks a lot for any help