asp.net mvc - How to Pass QueryString in MVC WEBAPI routing for the following URL -


i having following url. when enter url in browser passing values cant access api method in applcation. new mvc. not sure whether can pass querystring in mvc webapi routing.if possible, please pass querystring in mvc webapi routing.

http://localhost:1665/api/load/loaddetails?id={1}&latitude={2}&longitude={3}&uncertaint y={4}&street1={5}&street2={6}&neighborhood={7}&ci&locationdatetimeutc={12}  

in routeconfig have following code,

       config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{controller}",             defaults: new { action = "get" }         );          config.routes.maphttproute(             name: "defaultapiid",             routetemplate: "api/{controller}/{id:int}",             defaults: new { id = routeparameter.optional }         );          reportscontrollerconfiguration.registerroutes(config);         config.maphttpattributeroutes(); 

in apicontroller

       [routeprefix("load")]         public class loadcontroller : apicontroller         {         #region restful methods          [httpget]         [authorize()]              [route("saveintransitcheckcall/{id}/{latitude}/{longitude}/{uncertainty}/{street1}/{street2}/{neighborhood}/{city}/{state}/{postal}/{country}/")]         public httpresponsemessage saveintransitcheckcall(int id)         {} 

please access method. in advance.

if want pass parameters querystring parameters below url:

http://localhost:1665/api/load/loaddetails?id={1}&latitude={2}&longitude={3}&uncertaint y={4}&street1={5}&street2={6}&neighborhood={7}&ci&locationdatetimeutc={12}  

then use below code:

[httpget] [authorize()]  [route("saveintransitcheckcall")] public ihttpactionresult saveintransitcheckcall() {   var querystring = this.request.getquerynamevaluepairs();    var id = querystring.singleordefault(x => x.key == "id").value;   var latitude = querystring.singleordefault(x => x.key == "latitude").value;   //read other variables above     //do remaining code here } 

else can try below code restful method:

[httpget] [authorize()]      [route("saveintransitcheckcall/{id:int}/{latitude:decimal}/{longitude:decimal}/{uncertainty}/{street1}/{street2}/{neighborhood}/{city}/{state}/{postal}/{country}/")] public httpresponsemessage saveintransitcheckcall(int id, decimal latitude, decimal longitude, string uncertainty, string street1, string street2, string neighborhood, string city, string state, string postal, string country) {   //do remaining code here } 

please let me know, works you?


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -