Guest User

Untitled

a guest
Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. public class HomeController : Controller
  2. {
  3. public ActionResult Index()
  4. {
  5. return View();
  6. }
  7.  
  8. public ActionResult About()
  9. {
  10. return View();
  11. }
  12.  
  13. //... a public method for every view.. :(
  14. }
  15.  
  16. HomeController.About()
  17. HomeController.Features()
  18. HomeController.Index()
  19. HomeController.Testimonials()
  20. HomeController.ContactUs()
  21.  
  22. HomeController.About()
  23. HomeController.Features()
  24. HomeController.Index()
  25. HomeController.Testimonials()
  26. HomeController.ContactUs()
  27.  
  28. public class HomeController{
  29.  
  30. public ActionResult ShowBasicView(){
  31. //HTTP GET:
  32. //site.com/about
  33. //site.com/features
  34. //site.com/
  35. //site.com/testimonials
  36.  
  37. //All URLs above map to this action
  38.  
  39. return View();
  40. }
  41.  
  42. [AcceptVerbs(HttpVerbs.Post)]
  43. public ActionResult ContactUs(FormCollection data){
  44.  
  45. //HTTP POST:
  46. //site.com/contact-us
  47.  
  48. //POST URL maps here.
  49.  
  50. SmtpClient.Send(new MailMessage()) //etc...
  51. return View()
  52. }
  53.  
  54. }
  55.  
  56. public class HomeController{
  57.  
  58. public ActionResult ShowBasicView(){
  59. //HTTP GET:
  60. //site.com/about
  61. //site.com/features
  62. //site.com/
  63. //site.com/testimonials
  64.  
  65. //All URLs above map to this action
  66.  
  67. return View();
  68. }
  69.  
  70. [AcceptVerbs(HttpVerbs.Post)]
  71. public ActionResult ContactUs(FormCollection data){
  72.  
  73. //HTTP POST:
  74. //site.com/contact-us
  75.  
  76. //POST URL maps here.
  77.  
  78. SmtpClient.Send(new MailMessage()) //etc...
  79. return View()
  80. }
  81.  
  82. }
  83.  
  84. routes.MapRoute(
  85. "ShowBasic",
  86. "{id}",
  87. new { controller = "Home", action = "ShowBasicView", id = "home" }
  88. );
  89.  
  90. public class HomeController: Controller{
  91.  
  92. public ActionResult ShowBasicView(string pageName){
  93. // Do something here to get the page data from the Model,
  94. // and pass it into the ViewData
  95. ViewData.Model = GetContent(pageName);
  96.  
  97. // All URLs above map to this action
  98. return View();
  99. }
  100. }
  101.  
  102. public class HomeController: Controller{
  103.  
  104. public ActionResult ShowBasicView(string pageName){
  105. // All URLs above map to this action
  106. // Pass the page name to the view method to call that view.
  107. return View(pageName);
  108. }
  109. }
Add Comment
Please, Sign In to add comment