asp.net mvc获取路由对应的url

时间:2015-11-20 11:33:26

标签: asp.net-mvc url routes

我遇到了以下问题。我有一个网址,我想检查网址是否可以映射到我的RouteConfig中定义的任何路由。换句话说,我需要一种正确的方法来确定网址是否适合我的应用程序。

也许有人知道该怎么做?

1 个答案:

答案 0 :(得分:0)

For Example : Student is my contoller and having action method     StudentList then I need to write following code in RouteConfig.cs file.

StudentContoller.cs

        public List<Student> StudentList (StudentModel model)
        {
            /* Logic for Student List */
         return View(model);
        }


      RouteConfig.cs

     routes.MapRoute(
                name: "StudentList",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Student", action ="StudentList", id = UrlParameter.Optional }
     );