Skip to content

Commit

Permalink
Bug Fix of Issue #1 in GitHub (no dashes when Controller is not speci…
Browse files Browse the repository at this point in the history
…fied in Html.ActionLink for current Controller)
  • Loading branch information
Ata committed Aug 20, 2013
1 parent 03b98e1 commit 1848441
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions LowercaseDashedRoute.sln
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LowercaseDashedRouting", "LowercaseDashedRouting\LowercaseDashedRouting.csproj", "{60AF4435-A22E-4937-BEB6-7A6A4EDE832D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LowercaseDashedRouting.Test", "LowercaseDashedRouting.Test\LowercaseDashedRouting.Test.csproj", "{23716EC5-35C4-4CAC-849E-FFEB76F0FAB6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -13,6 +15,10 @@ Global
{60AF4435-A22E-4937-BEB6-7A6A4EDE832D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60AF4435-A22E-4937-BEB6-7A6A4EDE832D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60AF4435-A22E-4937-BEB6-7A6A4EDE832D}.Release|Any CPU.Build.0 = Release|Any CPU
{23716EC5-35C4-4CAC-849E-FFEB76F0FAB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23716EC5-35C4-4CAC-849E-FFEB76F0FAB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23716EC5-35C4-4CAC-849E-FFEB76F0FAB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23716EC5-35C4-4CAC-849E-FFEB76F0FAB6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 37 additions & 2 deletions LowercaseDashedRouting/DashedRouteHandler.cs
@@ -1,3 +1,5 @@
using System;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
Expand All @@ -15,10 +17,43 @@ protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var values = requestContext.RouteData.Values;

values["action"] = values["action"].ToString().Replace("-", "");
values["controller"] = values["controller"].ToString().Replace("-", "");
values["action"] = UnDash(values["action"].ToString());
values["controller"] = UnDash(values["controller"].ToString());

return base.GetHttpHandler(requestContext);
}

/// <summary>
/// Converts some/thing-here urls to Some/ThingHere
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private string UnDash(string path)
{
if (path.Length == 0)
return path;

var sb = new StringBuilder();

sb.Append(Char.ToUpperInvariant(path[0]));

for (int i = 1; i < path.Length; i++)
{
if (path[i] == '-')
{
if (i + 1 < path.Length)
{
sb.Append(Char.ToUpperInvariant(path[i + 1]));
i++;
}
}
else
{
sb.Append(path[i]);
}
}

return sb.ToString();
}
}
}

0 comments on commit 1848441

Please sign in to comment.