2013-09-29 3 views
2

나는 이것을 해결하는 방법이 아닙니다. MVC DB에서 데이터 가져 오기 및보기에 표시

나는) (테이블에서 데이터를 검색하는 기본 컨트롤러라는 거래

CONTROLLER 개인 NWBA_DBEntities의 DB는 = 새로운 NWBA_DBEntities있다;

public class StatementModel 
{ 

    [StringLength(50)] 
    [Display(Name="Transaction Type: ")] 
    public string TransactionType { get; set; } 

    [StringLength(50)] 
    [Display(Name = "AccountNumber")] 
    public string AccountNumber { get; set; } 



} 
내 문제가보기에, 나는 테이블의 값을 표시하는 것 질수있다

:

@model Login.Models.StatementModel 

@{ 
    ViewBag.Title = "Statements"; 
} 


<h2>Index</h2> 

<table> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.TransactionType) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.AccountNumber) 
     </th> 

     <th></th> 
    </tr> 

    @foreach (var item in Model) 
    { 
    <tr> 

    </tr> 
} 
</table> 

어떤 하나

도와주세요 수

public ActionResult Index() 
    { 
     var statements = db.Transactions.ToList(); 
     return View(statements); 

    } 

나는 기본 모델을

+0

Statement 모델에 값을 저장하지 않습니다. 컨트롤러의 Action 메서드에서. –

+0

어떻게해야합니까? – kayze

답변

4
public ActionResult Index() 
    { 
     var statementModel = from s in db.Transactions 
          select new StatementModel 
          { 
           TransactionType = s.TransactionType, 
           AccountNumber = s.AccountNumber 
          } 
     return View(statementModel); 

    } 
관련 문제