Guest User

Untitled

a guest
Aug 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Routing for .json and .xml
  2. Details(id)
  3. {
  4. $data = $this->MyController->findById(id);
  5.  
  6. if($this->requestType == "json")
  7. {
  8. respondAs("json");
  9. }
  10. else if($this->requestType == "xml")
  11. {
  12. respondAs("xml");
  13. }
  14. else
  15. {
  16. //does default - html view
  17. }
  18.  
  19. $this->setViewVariable("data", $data);
  20. }
  21.  
  22. routes.MapRoute(
  23. "Default",
  24. "{controller}/{action}/{id}/{type}",
  25. new { controller = "Home", action = "Index", id = UrlParameter.Optional, type = UrlParameter.Optional });
  26.  
  27. public ActionResult Index(int id, string type)
  28. {
  29. if(type == "json")
  30. return View("JsonView");
  31.  
  32. //etc
  33. }
Add Comment
Please, Sign In to add comment