MVC页面重定向----页面跳转

MVC页面重定向,主要有以下几种形式:

   1.Response.Redirect();方法

  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"] = "欢迎使用 ASP.NET MVC!";
  14. Response.Redirect( "User/News");
  15. return View();
  16. }
  17. public ActionResult About()
  18. {
  19. return View();
  20. }
  21. }
  22. }


 


     2.Return  Redirect();方法

  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"] = "欢迎使用 ASP.NET MVC!";
  14. return Redirect( "User/News");
  15. }
  16. public ActionResult About()
  17. {
  18. return View();
  19. }
  20. }
  21. }


 


      3.Return RedirectToAction();方法

该方法有两种重载(具体几种记不清了,就算两种吧)如下

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


转自:https://blog.csdn.net/lonestar555/article/details/7046717

猜你喜欢

转载自blog.csdn.net/qq_39657909/article/details/80888022
今日推荐