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

  • 相关阅读:
    DOM面试题【三】
    JS面试题【二】
    移动端面试题【一】
    【python】mysql查询错误告警的处理
    硬币排成线
    书籍复印
    分割回文串
    分割回文串 II
    完全平方数
    俄罗斯套娃信封问题
  • 原文地址:https://www.cnblogs.com/allenhua/p/3969133.html
Copyright © 2020-2023  润新知