我有这样的课
public class AmeInvoice
{
public DateTime invoiceDate { get; set; }
public string invoiceNumber { get; set; }
public string accountNumber { get; set; }
public double amount { get; set; }
public double amountDue { get; set; }
}
我有一个像这样的视图模型
public class AmeInvoiceViewModel
{
public List<AmeInvoice> ppInvoices { get; set; }
public double otherAmount { get; set; }
public double totalDue { get; set; }
}
我的控制器中的动作结果方法是这样的
public actionresult index ()
{
....
....
....
List<AmeInvoice> prideInvoices = new List<AmeInvoice>();
while (reader.Read())
{
prideInvoices.Add(new AmeInvoice()
{
invoiceDate = Convert.ToDateTime(reader["invoicedate"]),
invoiceNumber = reader["invoicenumber"].ToString(),
accountNumber = reader["account"].ToString(),
amount = Convert.ToDouble(reader["amount"]),
amountDue = Convert.ToDouble(reader["amountdue"])
});
}
var myviewModel = new AmeInvoiceViewModel();
myviewModel.ppInvoices = prideInvoices;
myviewModel.otherAmount = 20.20;
myviewModel.totalDue = 30.20;
return View(myviewModel);
}
在我看来我有这个
@model List<InSCmm.Web.Model.AmeInvoiceViewModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<table>
@foreach (InSCmm.Web.Model.AmeInvoiceViewModel objUser in Model)
{
<tr>
<td>@objUser.</td>
<td>@objUser.</td>
<td>@objUser.</td>
<td>@objUser.</td>
<td>@objUser.</td>
</tr>
}
</table>
我的问题:我对 Mvc 很陌生,我希望能够在我的视图中的表格中显示 invoiceDate、invoiceNumber、accountNumber、金额、应付金额。目前,如果我做一个 objUser。(我没有得到这些字段)请协助。这是正确的道路吗?