zoukankan      html  css  js  c++  java
  • asp.net mvc 页面调整并传递参数

     使用过ASP.NET MVC的人都知道在MVC中页面后台中常用的页面跳转方法有几种,如:return View()、return RedirectToAction()

        一般情况下我们返回的都是本页面,所以使用return View()就可以解决问题了,但是很多时候我们也会遇到返回的页面不是本页面的,那么就会用到后面两种,但是如果我们在页面返回的时候也要返回操作的结果的时候,我们就要对return RedirectToAction();方法进行扩展使用了。

       

    1. RedirectToAction(string ActionName);  
    2. RedirectToAction(string ActionName, object viewData);  
    3. RedirectToAction(string ActionName, string ControllerName);  
    4. RedirectToAction(string ActionName, string ControllerName, object viewData);  


    举例使用:

    1、跳转到同一Controller 里面的不同Action,如:HomeController里面的不同页面跳转到Index页面,RedirectToAction("Index");

    2、跳转到同一Controller 里面的不同Action,含参数,如:HomeController里面的不同页面跳转到Index页面,并传递msg="操作成功",RedirectToAction("Index",new {msg="操作成功"});

    3、跳转到不同Controller 里面的不同Action,如:其他Controller里面的页面跳转到HomeController里面的Index页面,RedirectToAction("Index","Home");

    2、跳转到不同Controller 里面的不同Action,含参数,如:其他Controller里面的页面跳转到HomeController里面的Index页面,并传递msg="操作成功",RedirectToAction("Index","Home",new {msg="操作成功"});

    传递多个参数类似:

    RedirectToAction("Index","Home",new {msg="操作成功",name="admin"});

    当然要使用传递参数的话参数名是要在Global.asax里面配置的,别忘记了。

  • 相关阅读:
    「题解」:$Six$
    「题解」:$Smooth$
    AFO
    纪念——代码首次达到近50K(更新:78.8K 2019行)
    meet-in-the-middle 基础算法(优化dfs)
    莫队学习笔记
    树链剖分学习笔记
    常用数论模板
    图论模板
    高精度模板(结构体封装,重载运算符)
  • 原文地址:https://www.cnblogs.com/bobo41/p/3028148.html
Copyright © 2011-2022 走看看