ASP.NET MVC页面重定向简单介绍(2)

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(); } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdpxpy.html