Browse files

Fixed issue with GetVirtualPathForArea. It appeared that controller a…

…nd action we're not specified properly. Thanks to John M. Holliday for the fix.
  • Loading branch information...
1 parent e48157f commit adb74495a93e0cea0680a08df008b9d08f4f4d5d @martijnboland committed Aug 15, 2011
View
17 src/MvcPaging.Demo/Global.asax.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Mvc;
+using System.Web.Mvc;
using System.Web.Routing;
namespace MvcPaging.Demo
@@ -13,10 +9,19 @@ public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
+
+ routes.MapRoute("Test1", "Test1",
+ new { controller = "Home", action = "About" },
+ new[] { "MvcPaging.Demo.Controllers" });
+
+ routes.MapRoute("SimplePaging", "SimplePaging/{page}",
+ new { controller = "Paging", action = "Index", page = UrlParameter.Optional },
+ new[] { "MvcPaging.Demo.Controllers" });
+
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
- new { controller = "Home", action = "Index", id = "" }, // Parameter defaults
+ new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "MvcPaging.Demo.Controllers" }
);
View
92 src/MvcPaging.Demo/Web.config
@@ -1,54 +1,48 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
-
<configuration>
- <appSettings>
- <add key="ClientValidationEnabled" value="true"/>
- <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
- </appSettings>
-
- <system.web>
- <compilation debug="true" targetFramework="4.0">
- <assemblies>
- <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- </assemblies>
- </compilation>
-
- <authentication mode="Forms">
- <forms loginUrl="~/cmsadmin/account/login" timeout="2880" />
- </authentication>
-
- <pages>
- <namespaces>
- <add namespace="System.Web.Helpers" />
- <add namespace="System.Web.Mvc" />
- <add namespace="System.Web.Mvc.Ajax" />
- <add namespace="System.Web.Mvc.Html" />
- <add namespace="System.Web.Routing" />
- <add namespace="System.Web.WebPages"/>
- <add namespace="MvcPaging"/>
- <add namespace="MvcPaging.Demo.Models"/>
- </namespaces>
- </pages>
- </system.web>
-
- <system.webServer>
- <validation validateIntegratedModeConfiguration="false"/>
- </system.webServer>
-
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
- <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
-</configuration>
+ <appSettings>
+ <add key="ClientValidationEnabled" value="true" />
+ <add key="UnobtrusiveJavaScriptEnabled" value="true" />
+ </appSettings>
+ <system.web>
+ <compilation debug="true" targetFramework="4.0">
+ <assemblies>
+ <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
+ <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
+ <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
+ <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
+ <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
+ </assemblies>
+ </compilation>
+ <authentication mode="Forms">
+ <forms loginUrl="~/cmsadmin/account/login" timeout="2880" />
+ </authentication>
+ <pages>
+ <namespaces>
+ <add namespace="System.Web.Helpers" />
+ <add namespace="System.Web.Mvc" />
+ <add namespace="System.Web.Mvc.Ajax" />
+ <add namespace="System.Web.Mvc.Html" />
+ <add namespace="System.Web.Routing" />
+ <add namespace="System.Web.WebPages" />
+ <add namespace="MvcPaging" />
+ <add namespace="MvcPaging.Demo.Models" />
+ </namespaces>
+ </pages>
+ </system.web>
+ <system.webServer>
+ <validation validateIntegratedModeConfiguration="false" />
+ </system.webServer>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
+ <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
View
13 src/MvcPaging/Pager.cs
@@ -94,6 +94,19 @@ public HtmlString RenderHtml()
private string GeneratePageLink(string linkText, int pageNumber)
{
var pageLinkValueDictionary = new RouteValueDictionary(linkWithoutPageValuesDictionary) { { "page", pageNumber } };
+
+ // To be sure we get the right route, ensure the controller and action are specified.
+ var routeDataValues = viewContext.RequestContext.RouteData.Values;
+ if (!pageLinkValueDictionary.ContainsKey("controller") && routeDataValues.ContainsKey("controller"))
+ {
+ pageLinkValueDictionary.Add("controller", routeDataValues["controller"]);
+ }
+ if (!pageLinkValueDictionary.ContainsKey("action") && routeDataValues.ContainsKey("action"))
+ {
+ pageLinkValueDictionary.Add("action", routeDataValues["action"]);
+ }
+
+ // 'Render' virtual path.
var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);
if (virtualPathForArea == null)
View
4 src/MvcPaging/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.1.0")]
+[assembly: AssemblyFileVersion("1.0.1.0")]

0 comments on commit adb7449

Please sign in to comment.