This is the view :
@model Northwind.Employee
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/MasterDetailsLayoutPage.cshtml";
}
<h2>Details</h2>
<div>
<h4>Employee</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.LastName)
</dt>
<dd>
@Html.DisplayFor(model => model.LastName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.FirstName)
</dt>
<dd>
@Html.DisplayFor(model => model.FirstName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.TitleOfCourtesy)
</dt>
<dd>
@Html.DisplayFor(model => model.TitleOfCourtesy)
</dd>
<dt>
@Html.DisplayNameFor(model => model.BirthDate)
</dt>
<dd>
@Html.DisplayFor(model => model.BirthDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.HireDate)
</dt>
<dd>
@Html.DisplayFor(model => model.HireDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Address)
</dt>
<dd>
@Html.DisplayFor(model => model.Address)
</dd>
<dt>
@Html.DisplayNameFor(model => model.City)
</dt>
<dd>
@Html.DisplayFor(model => model.City)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Region)
</dt>
<dd>
@Html.DisplayFor(model => model.Region)
</dd>
<dt>
@Html.DisplayNameFor(model => model.PostalCode)
</dt>
<dd>
@Html.DisplayFor(model => model.PostalCode)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Country)
</dt>
<dd>
@Html.DisplayFor(model => model.Country)
</dd>
<dt>
@Html.DisplayNameFor(model => model.HomePhone)
</dt>
<dd>
@Html.DisplayFor(model => model.HomePhone)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Extension)
</dt>
<dd>
@Html.DisplayFor(model => model.Extension)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Photo)
</dt>
<dd>
@{
byte[] photo = Model.Photo;
string imageSrc = "image / jpeg";
if (photo != null)
{
MemoryStream ms = new MemoryStream();
ms.Write(photo, 78, photo.Length - 78);
string imageBase64 = Convert.ToBase64String(ms.ToArray());
imageSrc = string.Format("data:image/jpeg;base64,{0}", imageBase64);
}
}
<img src="@imageSrc" alt="Image" width="50" height="50"/>
</dd>
<dt>
@Html.DisplayNameFor(model => model.Notes)
</dt>
<dd>
@Html.DisplayFor(model => model.Notes)
</dd>
<dt>
@Html.DisplayNameFor(model => model.PhotoPath)
</dt>
<dd>
@Html.DisplayFor(model => model.PhotoPath)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Employee1.LastName)
</dt>
<dd>
@Html.DisplayFor(model => model.Employee1.LastName)
</dd>
</dl>
</div>
<h4>Customers</h4>
<p>
@Html.ActionLink("Create New Customer", "Create", "Customers", new { id = Model.EmployeeID }, null)
</p>
<table class="table">
<tr>
<th>
Customer ID
</th>
<th>
Customer Name
</th>
<th></th>
</tr>
@foreach (var item in Model.Orders.Distinct<Order>())
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.CustomerID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Customer.ContactName)
</td>
<td>
@Html.ActionLink("Editt ", "Edit", "Customers", new { id = item.CustomerID }, null)
@Html.ActionLink("Detailss ", "Details", "Customers", new { id = item.CustomerID }, null)
@Html.ActionLink("Deletee ", "Delete", "Customers", new { id = item.CustomerID }, null)
@Html.ActionLink("Edit", "Edit", new { id = item.CustomerID }) |
@Html.ActionLink("Details", "Details", new { id = item.CustomerID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.CustomerID })
</td>
</tr>
}
</table>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.EmployeeID }) |
@Html.ActionLink("Back to List", "Index")
</p>
And this is the controller :
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Employee employee = db.Employees.Find(id);
if (employee == null)
{
return HttpNotFound();
}
return View(employee);
}
What i want is in the Customers section in the view to display DISTINCT customers of every employee ,but i cant do that , i dont know how:
@foreach (var item in Model.Orders.Distinct<Order>())
{
What I have tried:
I just explained the problem above