文章出處

//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();  
        }  
    }  
}  

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()