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;

        }

}

posted on 2014-11-17 15:13  六欲  阅读(282)  评论(0)    收藏  举报

导航