2

我不是 100% 如何解决这个问题。

我有一个基本控制器,它从名为 transactions 的表中检索数据

控制器私有 NWBA_DBEntities db = new NWBA_DBEntities();

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

    }

我有基本模型:

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>

有人可以帮忙吗

4

1 回答 1

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

    }
于 2013-09-29T07:45:13.663 回答