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方法

  • 相关阅读:
    【转】Android版本升级同时Sqlite数据库的升级及之前数据的保留
    MC 在1分钟图拿出5分钟,15分钟,30分钟,1小时的K线
    MC 自己平均
    MT4 做指标模版
    MQL5 获取最后一单 利润
    MT5基础知识
    DDE复盘流程
    安装lnmp(linux nginx mysql php)
    centos 7 切换运行模式
    安装 flash player
  • 原文地址:https://www.cnblogs.com/gygtech/p/8662536.html
Copyright © 2011-2022 走看看