Skip to content

Instantly share code, notes, and snippets.

@andrewdavey
Created November 15, 2010 17:05
Show Gist options
  • Save andrewdavey/700607 to your computer and use it in GitHub Desktop.
Save andrewdavey/700607 to your computer and use it in GitHub Desktop.
Extending view model wishlist
class CustomerController : Controller {
public ActionResult List() {
var customers = DB.GetAllCustomers();
ViewModel.Customers = customers;
ExtendViewModel<Customer>("Url", customer => Url.Action("details", new { customer.Id }));
return View();
}
public ActionResult Details(int id) {
// ...
}
}
// Then in the view page, use the viewmodel like this:
// <ul>
// @foreach (var customer in View.Customers) {
// <li><a href="@customer.Url">@customer.Name</a></li>
// }
// </ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment