0

My question has 2 parts:

1

My MVC project has folder structure like so:

folder structure

I want to create a link in the 'Create' page that links to the 'Savings' WebForm

I've tried adding this to the RouteConfig:

routes.MapPageRoute(
            "idea-savings-calculator",
            "Idea/Savings",
            "~/Views/Idea/Savings.aspx"
            );

but the default MVC MapRoute function:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

maps to the URL localhost:xxxx/Idea/Savings first and throws an error because there isn't an action called savings in the Idea controller Savings.

Edit: RouteConfig Class:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

                    routes.MapPageRoute(
            "idea-savings-calculator",
            "Idea/Savings",
            "~/Views/Idea/Savings.aspx"
            );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

    }
}

2

Below is a cut from the 'Create' View of the 'Idea' Controller URL: http://localhost:51946/Idea/Create Idea>Create>

(red box indicates where I'd like the link to the Savings WebForm)

The Savings WebForm is just a simple calculator; how would I pass the product from the calculations back to the above 'Create' page so that it can be displayed in the bottom text box? I'm guessing it would be as a parameter in the url that the Idea Controller can match? But... How?

Thanks!

Community
  • 1
  • 1
Jimmy
  • 2,191
  • 6
  • 25
  • 45
  • Does your MapPageRoute come before your default MVC MapRoute? It needs to as the default is greedy. – Netricity Apr 30 '13 at 15:44
  • If I put MapPageRoute first I get redirected to `http://localhost:51946/Idea/Savings?action=Index&controller=Idea` if I try to access any page under the Idea Controller – Jimmy Apr 30 '13 at 15:50
  • Have you looked at [Route Debugger](http://haacked.com/archive/2011/04/12/routedebugger-2.aspx) or [Glimpse](http://nuget.org/packages/Glimpse) to see what's happening with routing? I am successfully using routing very similar to yours to route friendly urls to legacy asp.net web forms. Maybe update your post with your complete RegisterRoutes method. – Colin Young Apr 30 '13 at 17:12
  • 1
    Forgot to ask, do you have `routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");` at the start of your routing? – Colin Young Apr 30 '13 at 19:14
  • use IRouteConstraint http://stackoverflow.com/questions/10178276/after-add-mappageroute-to-an-asp-net-mvc-project-the-site-stops-to-enter-in-hom – Jaider Dec 04 '13 at 01:25

1 Answers1

1

So to solve my first problem I moved the WebForms page 'Savings.aspx' to the route of my project and used the MapPageRoute after the MapRoute method.

routes.MapPageRoute(
"idea-savings-calculator",
"Idea/Savings",
"~/Savings.aspx"
);
Jimmy
  • 2,191
  • 6
  • 25
  • 45