MVC页面重定向,主要有以下几种形式:

1.Response.Redirect();方法

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace MvcDemo.Controllers
  7. {
  8. [HandleError]
  9. public class HomeController : Controller
  10. {
  11. public ActionResult Index()
  12. {
  13. ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
  14. Response.Redirect("User/News");
  15. return View();
  16. }
  17. public ActionResult About()
  18. {
  19. return View();
  20. }
  21. }
  22. }

2.Return  Redirect();方法

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace MvcDemo.Controllers
  7. {
  8. [HandleError]
  9. public class HomeController : Controller
  10. {
  11. public ActionResult Index()
  12. {
  13. ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
  14. return Redirect("User/News");
  15. }
  16. public ActionResult About()
  17. {
  18. return View();
  19. }
  20. }
  21. }

3.Return RedirectToAction();方法

该方法有两种重载(具体几种记不清了,就算两种吧)如下

    1. RedirectToAction(“ActionName”);//该方法直接写入页面,前提必须是在改控制器下问页面如前面的Index.aspx,和About.aspx
    2. RedirectToAction(“ActionName”,"ControllerName")//该方法直接写入ActionName和ControllerName,前提必须是在改控制器下问页面如前面的Index.aspx,和About.aspx
    3. using System;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6. using System.Web;
    7. using System.Web.Mvc;
    8. namespace MvcDemo.Controllers
    9. {
    10. [HandleError]
    11. public class HomeController : Controller
    12. {
    13. public ActionResult Index()
    14. {
    15. ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
    16. return RedirectToAction("News","User");
    17. }
    18. public ActionResult About()
    19. {
    20. return View();
    21. }
    22. }
    23. }

转自:http://blog.csdn.net/lonestar555/article/details/7046717

MVC页面重定向'页面跳转的更多相关文章

  1. Spring mvc后台重定向页面,实际前端不跳转

    1.ajax不支持重定向 ajax是不支持重定向的,因为ajax本身就是局部刷新,不重新加载页面的. 2.若后台出现需要重定向页面,可以设置唯一错误码 前端ajax公共调用后,凡是遇到这一类错误码,则 ...

  2. ASP.NET MVC之"重定向/页面跳转"(关键词RedirectToAction,Redirect)

    MVC5 API(官方) 1.RedirectToRouteResult RedirectToAction(string actionName); RedirectToRouteResult Redi ...

  3. MVC 访问IFrame页面Session过期后跳转到登录页面

    Web端开发时,用户登录后往往会通过Session来保存用户信息,Session存放在服务器,当用户长时间不操作的时候,我们会希望服务器保存的Session过期,这个时候,因为Session中的用户信 ...

  4. MVC小系列(十)【PartialView中的页面重定向】

    在mvc的每个Action中,都可以指定一种返回页面的类型,可以是ActionResult,这表示返回的页面为View或者是一个PartialView, 在以Aspx为页面引擎时,PartialVie ...

  5. spring mvc: 页面重定向调整

    我的项目名称是hello, 在src/main/java目录下面建了一个chapter2目录 有三个配置文件: web.xml, chapter2-servlet.xml, applicationCo ...

  6. HTML meta refresh 刷新与跳转(重定向)页面

    下面为各位整理了一些HTML meta refresh 刷新与跳转(重定向)页面的例子吧,后面本站长自己也补充了一些js页面刷新与跳转例子吧. refresh 属性值  --  刷新与跳转(重定向)页 ...

  7. Spring MVC页面重定向

    以下示例显示如何编写一个简单的基于Web的重定向应用程序,这个应用程序使用重定向将http请求传输到另一个页面. 基于Spring MVC - Hello World实例章节中代码,创建创建一个名称为 ...

  8. spring mvc helloworld 和表单功能、页面重定向

    Spring MVC Hello World 例子 这里有个很好的教程:https://www.cnblogs.com/wormday/p/8435617.html 下面的例子说明了如何使用 Spri ...

  9. response.sendRedirect 的功能是地址重定向(页面跳转)

    response.sendRedirect 的功能是地址重定向(页面跳转) 1.response.sendredirect(url); 新的页面并不能处理旧页面的pagecontext(request ...

随机推荐

  1. 中间件(middlebox)

    Middleboxes (also known as network functions) are systems that perform sophisticated and often state ...

  2. Xen虚拟化基本原理详解

    标签:虚拟化 xen 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://wangzan18.blog.51cto.com/80210 ...

  3. 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解

    看了很多nginx的配置,好像都忽略了ip直接访问web的问题,不利于SEO优化,所以我们希望可以避免直接用IP访问网站,而是域名访问,具体怎么做呢,看下面. 官方文档中提供的方法: If you d ...

  4. 选项卡js

    趁着公司不忙,抓紧充充电,开始可能会写的不好,但是每写一个都是一点进步,哈哈,加油 用js实现选项卡切换 1.获取元素 2.初始状态 3.通过循环清空元素状态 4.点击操作以及对应的内容切换 5.自定 ...

  5. Mysql Optimization Overview

    The information below i get from http://dev.mysql.com/doc/refman/8.0/en/optimize-overview.html Optim ...

  6. Java设计模式(五) 工厂模式

    1,定义抽象产品类 package com.pattern.factory; import java.util.ArrayList; public abstract class Pizza { Str ...

  7. nginx的安装

    1,,nginx的安装 为什么使用nginx我就不多说了,很优秀的,请再行google 在安装前,先安装pcre,安装zlib,安装openssl,以及一些其他包 yum install -y gcc ...

  8. 51nod 1013快速幂 + 费马小定理

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 这是一个等比数列,所以先用求和公式,然后和3^(n+1)有关,有n ...

  9. java:提示Could not initialize class sun.awt.X11GraphicsEnvironment

    前几天发现tomcat提示 Could not initialize class sun.awt.X11GraphicsEnvironment  问题.以为不验证,就没太关注,今天发现,有同事提示了个 ...

  10. 运行python代码报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 91: ordinal not in range(128)的解决办法

    1.通过搜集网上的资料,自己多次尝试,问题算是解决了,在代码中加上如下几句即可: import sys reload(sys) sys.setdefaultencoding('utf-8') 2.原因 ...