Asp.Net MVC中Action跳轉小結


https://www.cnblogs.com/surfing/p/3542826.html

 

首先我覺得action的跳轉大致可以這樣歸一下類,跳轉到同一控制器內的action和不同控制器內的action、帶有參數的action跳轉和不帶參數的action跳轉。

一、RedirectToAction("Index");//一個參數時在本Controller下,不傳入參數。

二、RedirectToAction(ActionName,ControllerName) //可以直接跳到別的Controller.

三、RedirectToRoute(new {controller="Home",action="Index"});//可跳到其他controller

四、RedirectToRoute(new {controller="Home",action="Index", id=param});//可跳到其他controller,帶參數。

五、Response.Redirect("Index?id=1");//適用於本controller下的方法名稱,可帶參數。
六、return Redirect("Index");//適用於本controller下的方法名稱。

七、return View("Index"); //直接顯示對應的頁面 不經過執行Controller的方法。 
八、return View("~/Views/Home/Index.aspx");//這種方法是寫全路徑,直接顯示頁面,不經過Controller方法
九、return View();//直接顯示頁面,不經過Controller方法

Don't go too far and forget why starting!


免責聲明!

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



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