//1.Response.Redirect
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"] = "欢迎使用 ASP.NET MVC!";  
            Response.Redirect("User/News");  
            return View();  
        }  
  
        public ActionResult About()  
        {  
            return View();  
        }  
    }  
}  

//2.Return  Redirect
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"] = "欢迎使用 ASP.NET MVC!";  
            return Redirect("User/News");  
        }  
  
        public ActionResult About()  
        {  
            return View();  
        }  
    }  
}  

//3.Return RedirectToAction
RedirectToAction(“ActionName”);//该方法直接写入页面,前提必须是在改控制器下问页面如前面的Index.aspx,和About.aspx  
  
RedirectToAction(“ActionName”,"ControllerName")//该方法直接写入ActionName和ControllerName,前提必须是在改控制器下问页面如前面的Index.aspx,和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"] = "欢迎使用 ASP.NET MVC!";  
            return RedirectToAction("News","User");  
        }  
  
        public ActionResult About()  
        {  
            return View();  
        }  
    }  
}  

 

相关文章:

  • 2022-02-18
  • 2021-05-14
  • 2021-12-09
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案