对于mvc来说很新5.如何使用剃须刀显示列表和字段
我有一个包含字段和列表的模型。
我希望在我看来都显示。
这是我的模型:
public class AdminChargeHistory
{
public List<StripeChargeHistory> Charges = new List<StripeChargeHistory>();
public string ErrorMessage { get; set;] }
}
public class StripeChargeHistory
{
public int TransactionId { get; set; }
public string Amount { get; set; }
public string AmountRefunded { get; set; }
public string CustomerId { get; set; }
public Nullable<bool> Paid { get; set; }
public string Status { get; set; }
public string ChargeId { get; set; }
public string InvoiceId { get; set; }
public string BalanceTransId { get; set; }
public Nullable<bool> Live { get; set; }
public Nullable<int> Month { get; set; }
public Nullable<int> Year { get; set; }
}
我的控制器:
public ActionResult MissedPayments()
{
var adminChargeHistory = new AdminChargeHistory();
try
{
var stripeRepository = new StripeRepository();
var results = stripeRepository.GetMissedPayments(-1, -1, false);
foreach (var result in results)
{
var stripeChargeHistory = new StripeChargeHistory();
stripeChargeHistory.Amount = result.Amount;
stripeChargeHistory.AmountRefunded = result.AmountRefunded;
stripeChargeHistory.BalanceTransId = result.BalanceTransId;
stripeChargeHistory.ChargeId = result.ChargeId;
stripeChargeHistory.CustomerId = result.CustomerId;
stripeChargeHistory.InvoiceId = result.InvoiceId;
stripeChargeHistory.Live = result.Live;
stripeChargeHistory.Month = result.Month;
stripeChargeHistory.Paid = result.Paid;
stripeChargeHistory.Status = result.Status;
stripeChargeHistory.TransactionId = result.TransactionId;
stripeChargeHistory.Year = result.Year;
adminChargeHistory.Charges.Add(stripeChargeHistory);
}
}
catch (Exception ex)
{
adminChargeHistory.ErrorMessage = ex.Message;
}
return View(adminChargeHistory);
}
我的观点:这里
@model InformedProducts.Models.AdminChargeHistory
@{
ViewBag.Title = "Missed Payments";
}
<h2>Missed Payments</h2>
<table class="grid">
<tr>
<th>Customer Id</th>
<th>Amount</th>
<th>Month</th>
<th>Year</th>
</tr>
@foreach (var item in Model.StripeChargeHistory)
{
<tr>
<td class="left"><@item.CustomerId></td>
<td class="left"><@item.Amount></td>
<td class="left"><@item.Month></td>
<td class="left"><@item.Year></td>
</tr>
@}
@Html.LabelFor(m=>m.ErrorMessage)
</table>
但错误:
InformedProducts.Models.AdminChargeHistory
和这里? @ Html.LabelFor(m => m.ErrorMessage)
我看不到我做错了什么?
'“但这里的错误”' - 错误是......? – David
刚才说的在设计视图中找不到 –
对于初学者来说,在你的'AdminChargeHistory'类中有一个输入错误会阻止它编译。所以你至少在编译之前不能使用它。编译器当然会告诉你关于*那个错误?至于“未找到”,你能否展示它的屏幕截图?通常有更具描述性的东西。 – David