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

hi,

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?

thanks
nicedoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
The first one is the classic querystring way supported natively by ASP.net:
replies?param1=3

The second is based on routes, which is a commonly used in the MVC designs.
You can still use routes in ASP.net webforms, but ASP.net 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? :)
0
nicedoneAuthor Commented:
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
0
Alexandre SimõesManager / Technology SpecialistCommented:
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
    [Route("reviews")]
    public ActionResult Index() { ... }
    // eg: /reviews/5
    [Route("reviews/{reviewId}")]
    public ActionResult Show(int reviewId) { ... }
    // eg: /reviews/5/edit
    [Route("reviews/{reviewId}/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:
    [Route("reviews/{reviewId}/edit")]
    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:
http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx

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...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.