简体   繁体   English

ASP.NET MVC 3 RC2错误?

[英]ASP.NET MVC 3 RC2 bug?

So far I've been using ASP.NET MVC 3 BETA. 到目前为止,我一直在使用ASP.NET MVC 3 BETA。 Everything was working fine till the update to RC2 version. 一切正常,直到更新到RC2版本。 Of course I've read ScottGu's article about RC2 . 当然,我已经阅读了ScottGu关于RC2的文章

My problem is following. 我的问题如下。 Basically I have 2 controllers: 基本上我有2个控制器:

   public class DynamicPageController : Controller
   {          
      public ActionResult Redirect(string resource, int? pageNumber, int? id)
      {       
      }
   }

   public class SystemController : Controller
   {
      public ActionResult Index()
      {
      }
   }

In the Globals.asax I have routes like this: 在Globals.asax中,我有这样的路线:

   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) 在两个版本(BETA和RC2)中,URL均为“ / my_app / System”

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. 给出在RC2中为null的url。 It should be (and in fact in BETA was) "/my_app/Home" 应该是(实际上在BETA中是)“ / my_app / Home”

Why ? 为什么呢 Is it a bug ? 是虫子吗? How can I create url for my " DynamicPage " controller ? 如何为“ DynamicPage ”控制器创建URL?

Regards 问候

BTW: From where can I now download ASP.NET MVC BETA version along with ASP.NET Web Pages 1.0 installers ? 顺便说一句:我现在可以从哪里下载ASP.NET MVC BETA版本以及ASP.NET Web Pages 1.0安装程序? Since RC2 announcement I have problems finding mentioned 2 installers. 自RC2发布以来,我很难找到提到的2个安装程序。 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. 通常,我会升级代码,但是上述问题使我在BETA呆了一段时间,因为我现在没有时间进行迁移和测试。

UPDATE 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: 我使用的情况下的解决方案,当我有现有陆续两个可选参数,是增加新的PageRouteCore路线之前存在PageRoute路线:

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. 现在,URL创建的行为符合我的预期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM