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非常陌生,我希望能够在我的视图中的表格中显示发票日期,发票编号,帐户编号,金额,金额。 目前,如果我做objUser。 (我没有得到这些领域) 请协助。这是正确的道路吗?
谢谢。此声明不起作用Total due:@ Html.DisplayFor(x => x.totalDue)。我无法访问totalDue。 – user2320476