0
創建付款時,我想在我的付款索引視圖中顯示ClientName。我從另一個名爲表中獲取客戶端名稱爲 「客戶」在我的視圖中顯示來自其他模型的數據
付款型號:
public class Payments
{
[Key]
public int PaymentsId { get; set; }
public int ClientsId { get; set; }
[ForeignKey("ClientsId")]
public virtual Clients Clients { get; set; }
public String Paymentnumber { get; set; }
public DateTime PaymentDate { get; set; }
public Decimal Amount { get; set; }
public Decimal Discount { get; set; }
public String Reference { get; set; }
public String Bank { get; set; }
}
付款控制器:
// GET: Payments
public ActionResult Index()
{
return View(db.PaymentsList.ToList());
}
付款索引視圖:
@model IEnumerable<localuh.Models.Payments>
....
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.Paymentnumber)</th>
<th>@Html.DisplayNameFor(model => model.PaymentDate)</th>
<th>@Html.DisplayNameFor(model => model.Amount)</th>
<th> @Html.DisplayNameFor(model => model.Discount)</th>
<th>@Html.DisplayNameFor(model => model.Reference)</th>
<th>@Html.DisplayNameFor(model => model.Bank)</th>
<th></th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.Paymentnumber)</td>
<td>@Html.DisplayFor(modelItem => item.PaymentDate)</td>
<td>@Html.DisplayFor(modelItem => item.Amount)</td>
<td>@Html.DisplayFor(modelItem => item.Discount)</td>
<td>@Html.DisplayFor(modelItem => item.Reference)</td>
<td>@Html.DisplayFor(modelItem => item.Bank)</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.PaymentsId }) |
@Html.ActionLink("Details", "Details", new { id=item.PaymentsId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.PaymentsId })
</td>
</tr>
}
</table>
那麼,我該怎麼做呢?
@StephenMuecke我改變所有建議 – Demain
需要一個麪包機k,但是你可以顯示'付款'的模型(它已經正確設置了它,它應該有一個'int ClientID'屬性和一個'虛擬客戶端客戶端'屬性),我會在30分鐘後看看。 –
'支付'模型(由'db.PaymentsList'返回的)',而不是'PaymentsViewModel' –