The media object component can be used to build hierarchal style lists such as blog comments or tweets. In our example application, we used the media object to return a search result view when the user searches for employees. As the
Northwind
database contains a field (ReportsTo
) that indicates which employee the other employees report to, the media object component would be ideal to indicate this visually. The method that searches for the employees and returns the results to the view is as follows:
public ActionResult SearchEmployeesResult(string query) { ViewBag.SearchQuery = query; var results = _context.Employees.Where(p => p.FirstName.Contains(query) || p.LastName.Contains(query) || p.Notes.Contains(query)).ToList(); return View(results); }
The view for the employee's search result uses the media object component to style the employee information and display the employee's photos as follows:
@model IEnumerable<Northwind.Data.Models...