can you explain me how to pass query string parameter in url vs. passing parameter as example /param1/2

nicedone used Ask the Experts™

i am trying to learn if i want to pass a parameter as param1/3   vs replies?param1=3

i would like to learn how to generate each of them what should i do, and which 1 i should prefer in my coding?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Alexandre SimõesManager / Solutions Architect

The first one is the classic querystring way supported natively by

The second is based on routes, which is a commonly used in the MVC designs.
You can still use routes in webforms, but MVC makes it easier to implement.

So to put it simple, the choice is much related to how you want to build your site, Web Forms or MVC? :)


thanks for the explaination,

1) if i use mvc which i do at the moment and prefer to pass in

replies?param1=3 can i do that? if so could you show a little code snippet that accomplishes that

if i want to use param1/3 as in routes could you share a small code to accomlish that insted too
Manager / Solutions Architect
The MVC routes don't work exactly like that.
The parameter name is not there, they are picked from where they are in the route.
For ex:
public class ReviewsController : Controller
    // eg: /reviews
    public ActionResult Index() { ... }
    // eg: /reviews/5
    public ActionResult Show(int reviewId) { ... }
    // eg: /reviews/5/edit
    public ActionResult Edit(int reviewId) { ... }

Open in new window

This means that the controller automatically maps the placeholder name with the method argument.

You can actually mix both routes and querystring in the same request:
    public ActionResult Edit(int reviewId, String name) { ... }

Open in new window

Can be called: reviews/123/edit?name=Alex

The example above was taken from here:

if i use mvc which i do at the moment and prefer to pass in replies?param1=3
Why would you want to do that anyway?
As I told you above, it's possible but you have to have a very specific reason for that...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial