2015-11-20 40 views
0

我面臨以下問題。我有一個url,我想檢查url是否可以映射到我的RouteConfig中定義的任何路由。換句話說,我需要一個正確的方式來確定URL是否適合我的應用程序。asp.net mvc獲取路由相應的網址

也許有人知道該怎麼做?

回答

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 } 
    );