1. 程式人生 > >MVC-RedirectToAction跳轉到其他Area

MVC-RedirectToAction跳轉到其他Area

system space gist clas 不同 override return 語句 fault

using System.Web.Mvc;

namespace web.Areas.FrameSet
{
    public class FrameSetAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "FrameSet";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "FrameSet_default",
                "FrameSet/{controller}/{action}/{id}",
                new { controller = "Frame", action = "Main", id = UrlParameter.Optional },
                new string[] { "web.Areas.FrameSet.Controllers" }
            );
        }
    }
}

再使用如下語句就可以在不同Area間跳轉:

return RedirectToAction("Main", "Frame", new { area = "FrameSet" });

再傳2個參數:

 return RedirectToAction("Main", "Frame", new { area = "FrameSet", a = 2, b = "b" });
?a=2&b=b

MVC-RedirectToAction跳轉到其他Area