MVC page redirect ' page jump

Source: Internet
Author: User
MVC page redirection is mainly in the following ways:

1.response.redirect (); method

     

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;

Namespace Mvcdemo.controllers
{
    [handleerror] public
    class Homecontroller:controller
    {
        Public ActionResult Index ()
        {
            viewdata["message"] = "Welcome to use ASP.net mvc!";
            Response.Redirect ("User/news");
            return View ();
        }

        Public ActionResult About ()
        {return
            View ();
        }
    }
}



2.Return Redirect () method

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;

Namespace Mvcdemo.controllers
{
    [handleerror] public
    class Homecontroller:controller
    {
        public ActionResult Index ()
        {
            viewdata["message"] = "Welcome to use ASP.net mvc!";
            Return Redirect ("User/news");

        Public ActionResult About ()
        {return
            View ();
        }
    }
}



3.Return redirecttoaction () method

This method has two kinds of overloads (the specific several can not remember clearly, even if two kinds of bar) are as follows

Redirecttoaction ("ActionName");//The method is written directly to the page, provided that the page is asked under the change controller, such as the preceding index.aspx, and About.aspx

redirecttoaction (" ActionName "," controllername ")//The method is written directly to ActionName and Controllername, subject to a change in the controller under the question page such as the front of the index.aspx, and About.aspx

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;

Namespace Mvcdemo.controllers
{
    [handleerror] public
    class Homecontroller:controller
    {
        Public ActionResult Index ()
        {
            viewdata["message"] = "Welcome to use ASP.net mvc!";
            Return redirecttoaction ("News", "User");
        }

        Public ActionResult About ()
        {return
            View ();
        }
    }
}

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.