ASP.NET MVC 3 RC2 bug?
So far I've been using ASP.NET MVC 3 BETA. Everything was working fine till the update to RC2 version. Of course I've read ScottGu's article about RC2.
My problem is following. Basically I have 2 controllers:
public class DynamicPageController : Controller
{
public ActionResult Redirect(string resource, int? pageNumber, int? id)
{
}
}
public class SystemController : Controller
{
public Actio开发者_JAVA技巧nResult Index()
{
}
}
In the Globals.asax I have routes like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"SystemRoute",
"System/{action}",
new { controller = "System", action = "Index" }
);
routes.MapRoute(
"PageRoute",
"{resource}/{id}/{pageNumber}",
new { controller = "DynamicPage", action = "Redirect", resource = UrlParameter.Optional, pageNumber = UrlParameter.Optional, id = UrlParameter.Optional }
);
}
In the code, I have simple link creation:
System.Web.Mvc.UrlHelper u = new System.Web.Mvc.UrlHelper(context);
string url = u.Action("Index", "System");
and the url is "/my_app/System" in both versions (BETA and RC2)
But the code below (the syntax is the same as above, only controller and action names are different):
string url = u.Action("Redirect", "DynamicPage", new RouteValueDictionary(new { resource = "Home" }));
gives url which is null in RC2. It should be (and in fact in BETA was) "/my_app/Home"
Why ? Is it a bug ? How can I create url for my "DynamicPage" controller ?
Regards
BTW: From where can I now download ASP.NET MVC BETA version along with ASP.NET Web Pages 1.0 installers ? Since RC2 announcement I have problems finding mentioned 2 installers. Normally I would upgrade my code but this issue described above makes me stay with BETA for a while, since I have no time for migration and testing everything now.
UPDATE
The solution I've used for the case, when I have two optional parameters existing one after another, is to add new PageRouteCore route just before existed PageRoute route:
routes.MapRoute(
"PageRouteCore",
"{resource}",
new {controller = "DynamicPage", action = "Redirect"}
);
This is basically the same route but without optional parameters. The url creation behaves now as I expected it to behave.
Yeah it's a bug.
Also you could download ASP.NET MVC RC1 from here.
精彩评论