0

I've been trying to pull the parameters passed into a page so I can post it back in Context.

So far,

        ViewBag.Message = string.Format("{0}::{1}::{2}",
        RouteData.Values["controller"],
        RouteData.Values["actions"],
        RouteData.Values["id"]);

works with anything simple like "66" or "tt" but anything more complex like "?name=blargh?viewId=66" and it fails.

I've tried a bunch of different ways to see if I could strike gold but nothing seems to work so does anybody have any idea what I'm missing/doing wrong/should be doing instead?

1 Answer 1

1

" but anything more complex like "?name=blargh?viewId=66" and it fails.

This doesn't seem to be routing information but query string which you should retrieve from the Request.QueryString bag.

If the {id} parameter is part of your route (as the default routes {controller}/{action}/{id}) I hope you realize that this id cannot be anything you like just because there are rules for an url. For example it cannot contain ? because this symbol has an entirely different meaning in an url - it represents the query string separator.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks I new there must of been something I was missing, once the accept timer runs out or on monday I'll mark this as accepted.
Yeah I was only setting it up to work on both just in case although I should only need to work with parameters, additionally do you know of good site that I should be able to further learn about routing and hoping a way to separate each query key so I wouldn't just be producing a single long url string.

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.