Created
November 15, 2010 17:05
-
-
Save andrewdavey/700607 to your computer and use it in GitHub Desktop.
Extending view model wishlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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