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

  • 相关阅读:
    Verilog语言
    OrCAD --从SNAPEDA导入封装库
    RAM/ROM IP一次性总结
    USB之Main item, Local item和Global item 的作用范围与归类
    发光LED压降与工作电流总结
    C之输入输出函数(3) -- 请使用sscanf()
    C之输入输出函数(2) -- gets()
    C之输入输出函数(1) -- fgets()
    C中的lvalue和rvalue
    关于字符串的一点补充
  • 原文地址:https://www.cnblogs.com/bobo41/p/3028148.html
Copyright © 2011-2022 走看看