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里面配置的,别忘记了。

  • 相关阅读:
    Angular 学习笔记 (消毒 sanitizer)
    资源链接
    QM作品
    读书笔记
    javascript jQuery遇到的小问题 不定添加
    css 平时遇见CSS的一些小技巧 不定添加
    html 小却重要的问题 不定添加
    Array 对象
    test
    Javascript定义类(class)的三种方法
  • 原文地址:https://www.cnblogs.com/allenhua/p/3969133.html
Copyright © 2011-2022 走看看