Asp.Net MVC中Action跳轉


  首先action的跳轉大致歸類:

  1跳轉到與當前同一控制器內的action和不同控制器內的action、

  2帶有參數的action跳轉和不帶參數的action跳轉。

  3跳轉到指定視圖,不經過Controller的Action。

  //跳轉到當前Controller的指定Action(此處為Index),不帶參數。

  一、RedirectToAction("Index");

  //跳轉到指定Controller下的指定Action,不帶闡述

  二、RedirectToAction(ActionName,ControllerName)

  //使用路由名稱和路由值重定向到指定的路由。不帶參數。

  三、RedirectToRoute(new {controller="Home",action="Index"});

  //使用路由名稱和路由值重定向到指定的路由。帶參數。

  四、RedirectToRoute(new {controller="Home",action="Index", id=param});

  //跳轉到當前controller下的Action,可帶參數。

  五、Response.Redirect("Index?id=1");

  //跳轉到當前controller下的Action,不帶參數。

  六、return Redirect("Index");

  //跳轉到當前路徑下的指定View(視圖),但不經過Action方法。

  七、return View("Index");

  //跳轉到指定路徑下的指定View(視圖),但不經過Action方法。這種方法是寫全路徑

  八、return View("~/Views/Home/Index.aspx");

  //跳轉到當前Controller,當前Action下的View。 最常見。

  九、return View();

  以上並沒有列舉完,因為還有多種重載,可以F12進步了解。

  (編輯:雷林鵬 來源:網絡)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM