c# System.Web.Mvc.UrlHelper.GenerateUrl method have a bug?
-
28-10-2019 - |
Вопрос
My English not wel, please bear with me a lot. routes in Global.asax file:
routes.MapRoute("Default","{controller}/{action}/{Page}/{id}",new { controller = "Home", action = "Index", Page = 0, id = UrlParameter.Optional });
I used @Html.Action write
@Html.ActionLink("LinkText","About",null,new{id="_ID"})
in View page. When opening url with
http://localhost/Home/About
in the broswer,The url result In the View page is:
http://localhost/Home/About
It's right! But When opening url with
http://localhost/Home/About/8
The url result In the View page is
http://localhost/Home/About/8
too. Why? This is a bug?
I want url is http://localhost/Home/About, Because the value of parameter named routeValues is null.
Решение
If you use null as your RouteValue then it will use the current RouteValues.
Rather use:
@Html.ActionLink("LinkText","About",new{page=0, id=""},new{id="_ID"})
Не связан с StackOverflow