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!

5
  • Does your MapPageRoute come before your default MVC MapRoute? It needs to as the default is greedy. Commented Apr 30, 2013 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 Commented Apr 30, 2013 at 15:50
  • Have you looked at Route Debugger or 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. Commented Apr 30, 2013 at 17:12
  • 1
    Forgot to ask, do you have routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); at the start of your routing? Commented Apr 30, 2013 at 19:14
  • use IRouteConstraint stackoverflow.com/questions/10178276/… Commented Dec 4, 2013 at 1:25

1 Answer 1

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"
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.