1
0
mirror of https://github.com/rudollee/LearningMVC.git synced 2026-08-11 16:32:55 +00:00

Ch. 16 Routing Adv (until 16-21)

This commit is contained in:
wook
2017-04-13 01:43:57 +09:00
parent 2fea7ffb5e
commit 59e0ccf99b
8 changed files with 130 additions and 9 deletions
@@ -17,10 +17,16 @@ namespace UrlsAndRoutes.Controllers
return View("ActionName");
}
[Route("Add/{user}/{id:int}")]
//[Route("Add/{user}/{id:int}")]
//public string Create(string user, int id)
//{
// return string.Format("User: {0}, ID: {1}", user, id);
//}
[Route("Add/{user}/{id:int}", Name = "AddRoute")]
public string Create(string user, int id)
{
return string.Format("User: {0}, ID: {1}", user, id);
return string.Format("Create Method - User: {0}, ID: {1}", user, id);
}
[Route("Add/{user}/{password:alpha:length(6)}")]
@@ -22,5 +22,23 @@ namespace UrlsAndRoutes.Controllers
ViewBag.CustomVariable = id; // ?? "<no value>"; // id; // RouteData.Values["id"];
return View();
}
//public ViewResult MyActionMethod()
//{
// string myActionUrl = Url.Action("Index", new { id = "MyID" });
// string myRouteUrl = Url.RouteUrl(new { controller = "Home", action = "Index" });
// return View();
//}
//public RedirectToRouteResult MyActionMethod()
//{
// return RedirectToAction("Index");
//}
public RedirectToRouteResult MyActionMethod()
{
return RedirectToRoute(new { controller = "Home", action = "Index", id = "MyID" });
}
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace UrlsAndRoutes.Controllers
{
public class LegacyController : Controller
{
public ActionResult GetLegacyURL(string legacyURL)
{
return View((object)legacyURL);
}
}
}