zoukankan      html  css  js  c++  java
  • Asp.Net MVC中Action跳转小结

    首先我觉得action的跳转大致可以这样归一下类,跳转到同一控制器内的action和不同控制器内的action、带有参数的action跳转和不带参数的action跳转。

    1、return View();//跳转到同方法名相同的本Controller下的视图

    2、return RedirectToAction("Add");//跳转到本Controller下其他方法,不是返回视图

    3、return RedirectToAction("Index", "Test");//跳转别的Controller方法

    4、return RedirectToRoute(new { controller = "Test", action = "Index" });//跳转控制器下的Action

    5、return RedirectToRoute(new { controller = "Test", action = "Index", id=1 });//可跳到其他controller,带参数。

    public ActionResult Index(int id)
    {
        ViewBag.ID = id;//Request["id"]这接收参数不行
        return View("MyView");
    }

    6、Response.Redirect("/Perpon/Add?id=1&name=hu");//本控制器下也需要写控制器名称

    public ActionResult Add(string name)
    {
        ViewData["id"] = Request["id"];//这种方式也能接收参数
        ViewData["name"] = name;
        return View();
    }

    7、return Redirect("/Perpon/Add?id=1&name=hu");//接收参数的方式与第6 相同

    8、return View("Index"); //直接显示对应的页面 不经过执行Controller的方法。 

    9、return View("/Views/Perpon/Add.cshtml");//这种方法是写全路径,直接显示页面,不经过Controller方法

  • 相关阅读:
    bzoj 3196/tyvj p1730 二逼平衡树
    AW201 可见的点 (欧拉函数)
    P3912 素数个数
    P1029 最大公约数和最小公倍数问题
    P1835 素数密度
    P2563 [AHOI2001]质数和分解
    P1075 质因数分解
    AW199 余数之和
    AW198 反素数
    AW197 阶乘分解
  • 原文地址:https://www.cnblogs.com/gygtech/p/8662536.html
Copyright © 2011-2022 走看看