zoukankan      html  css  js  c++  java
  • ASP.NET MVC 页面调整并传递参数

          转自:http://blog.csdn.net/zhensoft163/article/details/7174661  

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

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

       

    RedirectToAction(string ActionName);
    RedirectToAction(string ActionName, object viewData);
    RedirectToAction(string ActionName, string ControllerName);
    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里面配置的,别忘记了。

  • 相关阅读:
    MyBatis insert 返回主键的方法
    Linux实时网络监控工具:iftop
    深入理解Spring MVC 思想
    spring启动时加载字典表数据放入map
    mysql PROCEDURE ANALYSE() 用法
    http://www.cnblogs.com/shihaiming/
    maven 多模块项目
    分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群(转载-2)
    Nginx1.8.0版本平滑升级新版本1.9.7
    Linux 添加Nginx 到 service 启动
  • 原文地址:https://www.cnblogs.com/allenhua/p/3969133.html
Copyright © 2011-2022 走看看