Server side parameters

Hi Guys, i would like to know if it's possible to change the name of the server side variables sent in query string parameters.
In asp.net core, and i think in asp.net, i need to have into the method definition of the controllers, the same names of the variables to map with the [FromQuery] option (at the moment it's impossible to use this options because c# don't support the variables name starting with $ character).
In this way i don't need to invoke the function to read the variables from the querystring collection.
Thanks in advance
Stefano Capobianco

5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team October 27, 2017 05:13 PM UTC

Hi Stefano, 
 
Thanks for contacting Syncfusion support. 
 
According to your query you need to get the value from the variables of querystring collection. To read variables from querystring collection, use the below code example:  
 
 
[HttpGet] 
        public object Get() 
        { 
          var skip = Convert.ToInt32(Request.Query["$skip"]); 
          var top = Convert.ToInt32(Request.Query["$top"]); 
           
          }; 
        } 
 
Regards, 
Prasanna Kumar N.S.V 



SC Stefano Capobianco October 27, 2017 06:01 PM UTC

Hi tanks for your answer. I'm sorry but my english in not very fluent and maybe the question is not well exposed. I know how read a query string, my question is about the name of variables because to use the FromQuery option in asp.net c# the name of variable must be  the same as the parmaeter in the query string and is impossible to declare a variable who start with $.


Thanks 

Stefano Capobianco



VA Venkatesh Ayothi Raman Syncfusion Team October 31, 2017 02:20 PM UTC

Hi Stefano, 

Thanks for the update. 
  
We can access a variable which starts with $ as mentioned in previous update and this will not affect data operations in code behind. In sample browser sample for Grouping Grid the query string parameter will be passed as $top. Please refer the below given screenshot  
  
  
  
Also, refer the below given blog for further details  
  
  

Regards, 
Venkatesh Ayothiraman. 



SC Stefano Capobianco October 31, 2017 10:38 PM UTC

in c# it's impossible to declare a variable withe the name starting with th $ character. To use the FromQuery options in a mvc webapi controller the name of variable need to be the same as the variable passed as parameters:

Mvc controller declaration: public IActionResult methodname ([FromQuery] string variablename) 

Url with parameter: http://hostname/api/values?variablename=variablevalue.

I would like to know if the name of the variable sent by a datamanager with the webapiadaptor need to start with the $.

I know that i can read the values with the querystring function but to have the code muche clean i would like to use the fromquery option.

Thanks and best regards in advance

Stefano Capobianco



VA Venkatesh Ayothi Raman Syncfusion Team November 1, 2017 12:51 PM UTC

Hi Stefano, 

Thanks for the update. 

Response: Using “$” symbol in query option is the conventional rule.  
Please refer the link below:  
  
If you want to change the query, we suggest you to refer the custom adaptor 
  
We suggest you to override convertToQueryString internal method to change the query name that you wanted.   
By changing that, you can give the query option without dollar symbol in “([FromQuery] string variablename) ”.  
convertToQueryString: function (req, query, dm) {  
  
            var res = [], tableName = req.table || "";  
            delete req.table;  
  
            if (dm.dataSource.requiresFormat)  
                req["$format"] = "json";  
  
            for (var prop in req)  
                res.push(prop + "=" + req[prop]);  
  
            res = res.join("&");  
  
            if (dm.dataSource.url && dm.dataSource.url.indexOf("?") !== -1 && !tableName)  
                return res;  
              debugger;  
              res=res.replace(/[$]/g,"").replace(/select/,"$select");  
                
                                   
            return res.length ? tableName + "?" + res : tableName || "";  
        },  

Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon