Passing Values in a URL
I have a external link to my site which generates a URL lik开发者_StackOverflow社区e the below:
http://mywebsite.com/Account/?Number=25191108&Name=Something&Remote=False
I would like to be able to extract the values for Number, Name and Remote from this URL and route this URL to another page.
Could someone please suggest / give me some advice how to achieve this? I cannot adjust or alter this URL so I must extract this information from the URL as it is!
If you're using MVC, and I'm assuming you are because of the tags, your Controller can contain ActionResult and JsonResult methods, and those methods will have parameters. The parameters will automatically be read/parsed from the URL. So, given your URL, your Controller method would look like this.
public ActionResult MyMethod(int Number, string Name, bool Remote)
{
//do stuff.
}
foreach (string key in Request.QueryString.Keys )
{
var val = Request.QueryString[key].ToString();
//Add to collection, whatever
}
And then do whatever it is you need to do to redirect.
精彩评论