[英]ASP.NET MVC 3 RC2 bug?
到目前為止,我一直在使用ASP.NET MVC 3 BETA。 一切正常,直到更新到RC2版本。 當然,我已經閱讀了ScottGu關於RC2的文章 。
我的問題如下。 基本上我有2個控制器:
public class DynamicPageController : Controller
{
public ActionResult Redirect(string resource, int? pageNumber, int? id)
{
}
}
public class SystemController : Controller
{
public ActionResult Index()
{
}
}
在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 }
);
}
在代碼中,我有簡單的鏈接創建:
System.Web.Mvc.UrlHelper u = new System.Web.Mvc.UrlHelper(context);
string url = u.Action("Index", "System");
在兩個版本(BETA和RC2)中,URL均為“ / my_app / System”
但是下面的代碼(語法與上面的相同,只有控制器和動作名稱不同):
string url = u.Action("Redirect", "DynamicPage", new RouteValueDictionary(new { resource = "Home" }));
給出在RC2中為null的url。 應該是(實際上在BETA中是)“ / my_app / Home”
為什么呢 是蟲子嗎? 如何為“ DynamicPage ”控制器創建URL?
問候
順便說一句:我現在可以從哪里下載ASP.NET MVC BETA版本以及ASP.NET Web Pages 1.0安裝程序? 自RC2發布以來,我很難找到提到的2個安裝程序。 通常,我會升級代碼,但是上述問題使我在BETA呆了一段時間,因為我現在沒有時間進行遷移和測試。
UPDATE
我使用的情況下的解決方案,當我有現有陸續兩個可選參數,是增加新的PageRouteCore路線之前存在PageRoute路線:
routes.MapRoute(
"PageRouteCore",
"{resource}",
new {controller = "DynamicPage", action = "Redirect"}
);
這基本上是相同的路線,但沒有可選參數。 現在,URL創建的行為符合我的預期。
您也可以從此處下載ASP.NET MVC RC1 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.