tags:

views:

35

answers:

2

I've got an ASP.NET MVC site up and running, but need to make one slight change to it - but don't know how to approach it.

I've got a URL that looks like http://server/Oracle/Details/234342 - which displays information about customer number 234342.

Now I want to change the URL to this: http://server/Oracle/Details/234342?debug=1. I want to pick up the fact that debugging has been enabled to print out more info (like loadtime etc) on the webpage.

How do I accomplish this? I tried changing the default route, but then I ended up with http://server/Oracle/Details/234342/1 - which works, but isn't how I want my URL to look.

+1  A: 

You want to be checking Request.QueryString in your controller action for 'debug'. For example

[Route("Details/{nCustomer}")]
public ActionResult CustomerPage(int nCustomer)
{
    var debug = Request.QueryString["debug"];
    // More code goes here
}
Andrew Song
A: 

You don't need to change your routes to support this scenario. When generating links (e.g. via Html.ActionLink()), any parameters you provide that can't be mapped to route tokens will automatically be appended to the generated URL as query string parameters. And since the binder will automatically map query string parameters to action method parameters, you can do:

public ActionResult Details(int id, int? debug) {
  // you could also use a Boolean for 'debug' if you wanted, and it would bind true / false
}
Levi