When I create payment I want to display ClientName in my payment Index View. I get client name from another table called "Clients"
Payments Model:
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; }
}
Payments controller:
// GET: Payments
public ActionResult Index()
{
return View(db.PaymentsList.ToList());
}
Payment Index View:
@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>
So, how can I do that?