路由就是根据你输入的地址格式的不同,会匹配各自的路径
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default1",
url: "kfgl/{year}.{month}.{day}",
defaults: new { Controller="Home",action="Show", year = "2015", month = "1", day = "1" }
);
routes.MapRoute(
name: "Default3",
url: "find/{low}-{upp}",
defaults: new { controller = "Home", action = "FindByPrice" ,low=0,upp=100}
);
routes.MapRoute(
name: "Default2",
url: "{action}-{parent}",
defaults: new { Controller = "Home", action = "Show", parent="" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@*@Html.ActionLink("走第一个路径", "Show", new { year=2015, month=7,day=11})
@Html.ActionLink("走第二个路径", "ShowParent", new {parent="shandong"})*@
@using (Html.BeginForm("FindByPrice", "Home"))
{
<div>
最低价格:@Html.TextBox("low")
最高价格:@Html.TextBox("upp")
<input type="submit" value="查询" />
</div>
}
</div>
<div>@Html.Action("FindByPrice")</div>
</body>
</html>