Redirect to MVC page

Source: Internet
Author: User

MVC page redirection is mainly available in the following ways:

1.response.redirect (); method

[CSharp]View Plaincopy
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Linq;
  4. Using System.Web;
  5. Using SYSTEM.WEB.MVC;
  6. Namespace Mvcdemo.controllers
  7. {
  8. [HandleError]
  9. public class Homecontroller:controller
  10. {
  11. Public ActionResult Index ()
  12. {
  13. viewdata["Message" = "Welcome to ASP. mvc!";
  14. Response.Redirect ("user/news");
  15. return View ();
  16. }
  17. Public ActionResult About ()
  18. {
  19. return View ();
  20. }
  21. }
  22. }


2.Return Redirect (); method

[CSharp]View Plaincopy
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Linq;
  4. Using System.Web;
  5. Using SYSTEM.WEB.MVC;
  6. Namespace Mvcdemo.controllers
  7. {
  8. [HandleError]
  9. public class Homecontroller:controller
  10. {
  11. Public ActionResult Index ()
  12. {
  13. viewdata["Message" = "Welcome to ASP. mvc!";
  14. return Redirect ("user/news");
  15. }
  16. Public ActionResult About ()
  17. {
  18. return View ();
  19. }
  20. }
  21. }



3.Return redirecttoaction (); method

There are two kinds of overloads for this method (some of which are not clear, even if two kinds of bars) are as follows

[CSharp]View Plaincopy
    1. Redirecttoaction ("ActionName"); //The method is written directly to the page, as long as the controller is under the Index.aspx page as in the previous, and About.aspx
    2. Redirecttoaction ("ActionName","Controllername")//The method is written directly to ActionName and Controllername, The premise must be to change the controller under the question page as in front of the index.aspx, and About.aspx
    3. Using System;
    4. Using System.Collections.Generic;
    5. Using System.Linq;
    6. Using System.Web;
    7. Using SYSTEM.WEB.MVC;
    8. Namespace Mvcdemo.controllers
    9. {
    10. [HandleError]
    11. public class Homecontroller:controller
    12. {
    13. Public ActionResult Index ()
    14. {
    15. viewdata["Message" = "Welcome to ASP. mvc!";
    16. return Redirecttoaction ("News","User");
    17. }
    18. Public ActionResult About ()
    19. {
    20. return View ();
    21. }
    22. }
    23. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.