问题描述
我是新来的ASPNET MVC路由..我有以下code:
动作控制器
i'm new to routing in aspnet mvc.. i have following code: Action Controller
public ActionResult SchoolIndex()
{
return View(SchoolRepository.GetAllSchools());
}
下面是路由
routes.MapRoute(
"School", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "School", action = "SchoolIndex", id = "" } ); // Parameter defaults
当我输入地址栏本地主机/学校,这是给404错误,而不是它应该给我的schoolIndex行动路线
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 ?
推荐答案
您不能在URI指定路由名称,直到永远。
You can't specify a route name in a URI, ever.
路线名称是,例如, Html.RouteLink()
。 RouteLink
允许您指定正是你想要的路线,即使它不适合你传递参数的第一个匹配的路由。
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.
URI是为了匹配。第一个匹配的路由获胜。
URIs are matched in order. The first matching route wins.
我张贴在路由了解更多的细节。
这篇关于在哪里使用ASPNET MVC路由的路由名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!