MVC 自定义路由
1. MVC 自定义路由 的默认参数,通过Request 是拿不到值的,可以在 action 的括号里面获取到值 ,如:
routes.MapRoute(
name: "ChanYouJi",
url: "Chan/{action}/{activity}",
defaults: new { controller = "exchange", action = "Common", activity = "Chan" },
namespaces: new string[] { "Mimo.Web.Controllers" }
);
public ActionResult Common(string tplName, string activity = "")
{
if (string.IsNullOrWhiteSpace(activity))
{
//如果是通过:/Chan 跳转的 下面的获取参数方法是拿不到值的
activity = Request["activity"] as string;
}
}
浙公网安备 33010602011771号