MVC-RedirectToAction跳轉到其他Area


mvc使用Area分區開發后,存在不同Area之間的跳轉,需要為每個區間添加Area規則,如下:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM