zoukankan      html  css  js  c++  java
  • MVC入门学习笔记(五)

    四。MVC页面重定向

           

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

      

         1.Response.Redirect();方法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    namespace MvcDemo.Controllers
    {
        [HandleError]
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
                Response.Redirect("User/News");
                return View();
            }

            public ActionResult About()
            {
                return View();
            }
        }
    }


         2.Return  Redirect();方法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    namespace MvcDemo.Controllers
    {
        [HandleError]
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
                return Redirect("User/News");
            }

            public ActionResult About()
            {
                return View();
            }
        }
    }


          3.Return RedirectToAction();方法

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

    RedirectToAction(“ActionName”);//该方法直接写入页面,前提必须是在改控制器下问页面如前面的Index.aspx,和About.aspx

    RedirectToAction(“ActionName”,"ControllerName")//该方法直接写入ActionName和ControllerName,前提必须是在改控制器下问页面如前面的Index.aspx,和About.aspx

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    namespace MvcDemo.Controllers
    {
        [HandleError]
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
                return RedirectToAction("News","User");
            }

            public ActionResult About()
            {
                return View();
            }
        }
    }

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mane_yao/archive/2010/07/07/5718513.aspx

  • 相关阅读:
    S3C44b0x通用延时函数,延时time个100us函数理解
    LeetCode-058-最后一个单词的长度
    LeetCode-053-最大子序和
    LeetCode-035-搜索插入位置
    LeetCode-027-移除元素
    LeetCode-026-删除有序数组中的重复项
    LeetCode-025-K 个一组翻转链表
    LeetCode-024-两两交换链表中的节点
    LeetCode-023-合并K个升序链表
    LeetCode-021-合并两个有序链表
  • 原文地址:https://www.cnblogs.com/mane/p/1830082.html
Copyright © 2011-2022 走看看