cpoDesign
cpoDesign

Reputation: 9153

How do I route a webforms page in ASP.NET MVC?

I have an MVC page that has a webforms page that it needs to render:

The virtual directory for the webforms page is:

http://mysite/Report/1

File saved:

~/Areas/Accounts/Views/Invoices/Report.aspx?id=1

How do I map this?

I have mapped it to controller:

return Redirect("~/Areas/Accounts/Views/Invoices/Report.aspx?id=1?id=" + id);

But I get an error.

Upvotes: 2

Views: 2831

Answers (2)

George Stocker
George Stocker

Reputation: 57907

You want to use the MapPageRoute() method to send something to a specific page:

routes.MapPageRoute(
 "ReportRoute",
 "Report/{id}",
 "~/Areas/Accounts/Views/Invoices/Report.aspx?id={id}"   
 );

Upvotes: 3

gideon
gideon

Reputation: 19465

From the way you put it you might not be clear on what you're doing.

  1. Add a Controller (from visual studio) in this folder : ~/Areas/Accounts/Controllers/Report

    You would probably have a method display(int id) in your ReportController class. Then by default your URl will look like:

    http://mysite/Report/display/1
    
  2. To customize it you add this into Global.asax.cs :

    routes.MapRoute(
    "NewRoute", // Route name
    "report/{id}", // URL with parameters
     new { controller = "report", action = "display", // Parameter defaults
     id = UrlParameter.Optional }
    );
    

Upvotes: 0

Related Questions