ASP.NETMVC3Webアプリケーションで。
私は見解を持っています。ビューにはIEnumerableモデルがあります。
モデルのすべてのアイテムをループして、item.Nameを表示する必要があります。
景色:
@model IEnumerable<Object>
@{
ViewBag.Title = "Home";
}
@foreach (var item in Model)
{
<div class="itemName">@item.Name</div>
}
コントローラでは、Linq toエンティティを使用して、データベースからオブジェクトのリストを取得します。
コントローラー:
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();
}
実行すると、次のエラーが発生します。
'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?)
モデルアイテムの「名前」プロパティにアクセスするにはどうすればよいですか?
助けてくれてありがとう