보기의 개체 속성에 액세스합니다.MVC3 : ASP.NET MVC3 웹 응용 프로그램에서
나는 전망이있다. 뷰에는 IEnumerable 모델이 있습니다.
나는 모든 모델의 항목을 통해 루프 필요
에보기 item.Name을 보여 컨트롤러에서
@model IEnumerable<Object>
@{
ViewBag.Title = "Home";
}
@foreach (var item in Model)
{
<div class="itemName">@item.Name</div>
}
, 나는 개체의 목록을 얻을 엔티티에 Linq에를 사용 데이터베이스에서.
감사관 :
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?)
는 어떻게 모델 항목의 "이름"속성에 액세스 할 수 있습니까?
감사합니다 도움이
... – jrummell
에 나는 제대로 형식으로 코드를 얻을 수 없습니다. –
은 작은 따옴표를 사용하고있었습니다. –