Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC- How to get parameter value from get request which has parameter names including dot characters

In MVC, I know we can get parameters from a get request like this:

Request:

http://www.example.com/method?param1=good&param2=bad 

And in controller

public ActionResult method(string param1, string param2) {    .... } 

But in my situation an external website sends me a get request like:

http://www.example.com/method?param.1=good&param.2=bad 

And in controller when i try to meet this request like as follow:

public ActionResult method(string param.1, string param.2) {    .... } 

I get build errors because of dot in variable name. How can i get these parameters ? Unfortunately i can not ask them to change parameter names.

like image 804
nooaa Avatar asked Feb 17 '14 15:02

nooaa


People also ask

How do you pass multiple parameters in route attribute?

you could add a route like: routes. MapRoute( "ArtistImages", // Route name "{controller}/{action}/{artistName}/{apikey}", // URL with parameters new { controller = "Home", action = "Index", artistName = "", apikey = "" } // Parameter defaults );

How do you add parameters in GET request?

To do http get request with parameters in Angular, we can make use of params options argument in HttpClient. get() method. Using the params property we can pass parameters to the HTTP get request. Either we can pass HttpParams or an object which contains key value pairs of parameters.


1 Answers

Use the following code:

    public ActionResult method()     {         string param1 = this.Request.QueryString["param.1"];         string param2 = this.Request.QueryString["param.2"];          ...     } 
like image 122
ssimeonov Avatar answered Sep 24 '22 04:09

ssimeonov