Вы можете написать собственный маршрут:
public class BlogRoute : Route
{
public BlogRoute()
: base(
"blog/{*info}",
new RouteValueDictionary(new
{
controller = "blog",
action = "index"
}),
new MvcRouteHandler()
)
{
}
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var rd = base.GetRouteData(httpContext);
if (rd == null)
{
return null;
}
var info = rd.Values["info"] as string;
if (string.IsNullOrEmpty(info))
{
return rd;
}
var parts = info.Split('/');
if (parts.Length < 1)
{
return rd;
}
for (int i = 0; i < parts.Length; i++)
{
if (i == parts.Length - 1)
{
int page;
if (int.TryParse(parts[i], out page))
{
rd.Values["page"] = page;
}
}
if (!rd.Values.ContainsKey("page"))
{
rd.Values[string.Format("tags[{0}]", i)] = parts[i];
}
}
return rd;
}
}
, который будет зарегистрирован в Global.asax
:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add("BlogRoute", new BlogRoute());
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
, и тогда у вас может быть BlogController:
public class BlogController : Controller
{
public ActionResult Index(string[] tags, int? page)
{
...
}
}