public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.MapMvcAttributeRoutes(); //自定義路由 } }
[Route("Test")] public ActionResult About() { ViewBag.Message = "Your application description page."; return View(); }
[Route("")] public ActionResult Index() { return View(); }
[Route("")] [Route("home")] [Route("home/index")] public ActionResult Index() { return View(); }
[Route("Test/{id}")] public ActionResult About(int id) { ViewBag.Message = "Your application description page."; return View(); }
[Route("home/{action}")] public class HomeController : Controller { //[Route("")] //[Route("home")] //[Route("home/index")] public ActionResult Index() { return View(); } public ActionResult About(int id) { ViewBag.Message = "Your application description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } } }
[Route("")] [Route("home")] [Route("home/index")] public ActionResult Index() { return View(); }
寫得有點凌亂,改天有時間修改app