I was able to achieve something like this. Check it out:
First, I created a controller for testing this:
public class RoutesController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
}
In one of the existing views (apart from the 2 views below) I added this:
<%= Html.RouteLink("urls", "Custom") %>
Then a Index and About view under Views/Routes as shown below:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
index.mvc
<br />
<%= Html.RouteLink("more","ResponseExtension", new { datatype = "json" }) %>
</asp:Content>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
About
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>About</h2>
</asp:Content>
Then add the following to your RegisterRoutes:
routes.MapRoute("Custom", "routes/index.mvc", new { controller = "Routes", action = "Index" });
routes.MapRoute("ResponseExtension",
"testpg/about.{datatype}",
new
{
controller = "Routes",
action = "About",
datatype = @"\[a-z]+"
});
It worked fine for me! Give it a try!!
EDIT - If I changed testpg/about.{datatype} to testpg/{action}.{datatype} it didn't work though. I will try that out too when I find some time!