對於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