Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. route to reflect hierarchical url/menu structure
  2. public class FoodController : Controller
  3. {
  4.   public ActionResult ViewDishByTag(string itemType, string itemTag)
  5.   {
  6.  
  7.     // If an itemType is displayed without itemTag, return an 'index' list of possible dishes...
  8.  
  9.     // Alternatively, either return a "static" view of your page, e.g.
  10.     if (itemTag== "pad-thai")
  11.          return View("PadThai"); // where PadThai is a view in your shared views folder
  12.  
  13.      // Alternatively, look up the dish information in a database and bind return it to the view
  14.      return ("RecipeView", myRepo.GetDishByTag(itemTag));
  15.   }
  16. }
  17.        
  18. routes.MapRoute(
  19.                 "myRoute",
  20.                 "{controller}/{itemType}/{itemTag}",
  21.                 new
  22.                 {
  23.                     controller = UrlParameter.Required,
  24.                     action = "ViewDishByTag",
  25.                     itemtype = UrlParameter.Optional,
  26.                     itemTag = UrlParameter.Optional
  27.                 }
  28.             );