开发者

where to use route-name of routing in aspnet mvc

开发者 https://www.devze.com 2022-12-31 12:49 出处:网络
i\'m new to routing in aspnet mvc.. i have following code: Action Controller public ActionResult SchoolIndex()

i'm new to routing in aspnet mvc.. i have following code: Action Controller


public ActionResult SchoolIndex()
{
    return View(SchoolRepository.GetAllSchools());
}

here is the routing


routes.MapRoute(
"School",                                              // Route name
"{controller}/{action}/{id}",                           // URL with parameters
new { controller = "School", action = "SchoolIndex", 开发者_运维技巧id = "" } ); // Parameter defaults


when i enter "localhost/school" in addressbar, it is giving 404 error instead it should route to my "schoolIndex" action

i have given route-name as "School" where it is used ?


You can't specify a route name in a URI, ever.

Route names are for, e.g., Html.RouteLink(). RouteLink allows you to specify exactly the route you want, even if it's not the first matching route for the arguments you pass.

URIs are matched in order. The first matching route wins.

Read my post on routing for much more detail.

0

精彩评论

暂无评论...
验证码 换一张
取 消