Get string with multiple parameters in api controller and parse itASP.NET MVC - passing parameters to the controllerHow do I parse a string to a float or int?Can you overload controller methods in ASP.NET MVC?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I create a simple 'Hello World' module in Magento?parse url to get controller and action in Kohana 3Multiple types were found that match the controller named 'Home'Returning http status code from Web Api controllerIf my interface must return Task what is the best way to have a no-operation implementation?Why not inherit from List<T>?

The speed of a boat is 5Km/h in still water. It crosses a river of width 1km along the shortest path in 15 minutes.

Sloth and the Hindrances

Stack class in Java 8

What is the difference between a translation and a Galilean transformation?

A puzzling nature walk

A PEMDAS issue request for explanation

Aftermarket seats

After a few interviews, What should I do after told to wait?

Gap in tcolorbox after title

Yet another calculator problem

How can Schrödinger's cat be both dead and alive?

I multiply the source, you (probably) multiply the output!

Need help to understand the integral rules used solving the convolution of two functions

UK citizen travelling to France at the end of November

What is the name/purpose of this component?

How to descend a few exposed scrambling moves with minimal equipment?

Can you mark a new target with the Hunter's Mark spell if the original target shifts to a different plane?

Why can't some airports handle heavy aircraft while others do it easily (same runway length)?

What is this sticking out of my wall?

If every star in the universe except the Sun were destroyed, would we die?

More than three domains hosted on the same IP address

Is it unavoidable taking shortcuts in software development sometimes?

Are these 2 equivalent?

Isn't that (two voices leaping to C like this) a breaking of the rules of four-part harmony?



Get string with multiple parameters in api controller and parse it


ASP.NET MVC - passing parameters to the controllerHow do I parse a string to a float or int?Can you overload controller methods in ASP.NET MVC?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I create a simple 'Hello World' module in Magento?parse url to get controller and action in Kohana 3Multiple types were found that match the controller named 'Home'Returning http status code from Web Api controllerIf my interface must return Task what is the best way to have a no-operation implementation?Why not inherit from List<T>?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















This method accepts this type of uri:



/method?a=1&b=2&c=3

[Route("method")]
public string Get(string a, string b, string c)

return "ok";



But if I change uri to something different
let' say /method?a=1&b=2
then the method won't work.



How can I write controller action in the way that it will GET any type of string after "?" sign and then parse it as components ?










share|improve this question






























    0















    This method accepts this type of uri:



    /method?a=1&b=2&c=3

    [Route("method")]
    public string Get(string a, string b, string c)

    return "ok";



    But if I change uri to something different
    let' say /method?a=1&b=2
    then the method won't work.



    How can I write controller action in the way that it will GET any type of string after "?" sign and then parse it as components ?










    share|improve this question


























      0












      0








      0








      This method accepts this type of uri:



      /method?a=1&b=2&c=3

      [Route("method")]
      public string Get(string a, string b, string c)

      return "ok";



      But if I change uri to something different
      let' say /method?a=1&b=2
      then the method won't work.



      How can I write controller action in the way that it will GET any type of string after "?" sign and then parse it as components ?










      share|improve this question














      This method accepts this type of uri:



      /method?a=1&b=2&c=3

      [Route("method")]
      public string Get(string a, string b, string c)

      return "ok";



      But if I change uri to something different
      let' say /method?a=1&b=2
      then the method won't work.



      How can I write controller action in the way that it will GET any type of string after "?" sign and then parse it as components ?







      c# parsing controller get






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 7:24









      DavidDavid

      1,8637 gold badges37 silver badges71 bronze badges




      1,8637 gold badges37 silver badges71 bronze badges

























          3 Answers
          3






          active

          oldest

          votes


















          1
















          You can pass default values to the parameter



          /method?a=1&b=2&c=3

          [Route("method")]
          public string Get(string a= "", string b = "", string c = "")

          return "ok";



          Now it will work for



          /method
          /method?a=1
          /method?b=2
          /method?c=3


          and all combinations






          share|improve this answer
































            1
















            You can make it a optional parameter like



            [Route("method")]
            public string Get(string a, string b, string c = "")

            return "ok";






            share|improve this answer
































              0
















              I think this problem has been solved in some releases of MVC4 and you should define the default value for the parameters like below:



              [Route("method")]
              public string Get(string a = "", string b = "", string c = "")

              return "ok";






              share|improve this answer



























                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );














                draft saved

                draft discarded
















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392141%2fget-string-with-multiple-parameters-in-api-controller-and-parse-it%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1
















                You can pass default values to the parameter



                /method?a=1&b=2&c=3

                [Route("method")]
                public string Get(string a= "", string b = "", string c = "")

                return "ok";



                Now it will work for



                /method
                /method?a=1
                /method?b=2
                /method?c=3


                and all combinations






                share|improve this answer





























                  1
















                  You can pass default values to the parameter



                  /method?a=1&b=2&c=3

                  [Route("method")]
                  public string Get(string a= "", string b = "", string c = "")

                  return "ok";



                  Now it will work for



                  /method
                  /method?a=1
                  /method?b=2
                  /method?c=3


                  and all combinations






                  share|improve this answer



























                    1














                    1










                    1









                    You can pass default values to the parameter



                    /method?a=1&b=2&c=3

                    [Route("method")]
                    public string Get(string a= "", string b = "", string c = "")

                    return "ok";



                    Now it will work for



                    /method
                    /method?a=1
                    /method?b=2
                    /method?c=3


                    and all combinations






                    share|improve this answer













                    You can pass default values to the parameter



                    /method?a=1&b=2&c=3

                    [Route("method")]
                    public string Get(string a= "", string b = "", string c = "")

                    return "ok";



                    Now it will work for



                    /method
                    /method?a=1
                    /method?b=2
                    /method?c=3


                    and all combinations







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 28 at 7:31









                    Prasad TelkikarPrasad Telkikar

                    4,7442 gold badges8 silver badges28 bronze badges




                    4,7442 gold badges8 silver badges28 bronze badges


























                        1
















                        You can make it a optional parameter like



                        [Route("method")]
                        public string Get(string a, string b, string c = "")

                        return "ok";






                        share|improve this answer





























                          1
















                          You can make it a optional parameter like



                          [Route("method")]
                          public string Get(string a, string b, string c = "")

                          return "ok";






                          share|improve this answer



























                            1














                            1










                            1









                            You can make it a optional parameter like



                            [Route("method")]
                            public string Get(string a, string b, string c = "")

                            return "ok";






                            share|improve this answer













                            You can make it a optional parameter like



                            [Route("method")]
                            public string Get(string a, string b, string c = "")

                            return "ok";







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 28 at 7:30









                            RahulRahul

                            65.1k12 gold badges48 silver badges87 bronze badges




                            65.1k12 gold badges48 silver badges87 bronze badges
























                                0
















                                I think this problem has been solved in some releases of MVC4 and you should define the default value for the parameters like below:



                                [Route("method")]
                                public string Get(string a = "", string b = "", string c = "")

                                return "ok";






                                share|improve this answer





























                                  0
















                                  I think this problem has been solved in some releases of MVC4 and you should define the default value for the parameters like below:



                                  [Route("method")]
                                  public string Get(string a = "", string b = "", string c = "")

                                  return "ok";






                                  share|improve this answer



























                                    0














                                    0










                                    0









                                    I think this problem has been solved in some releases of MVC4 and you should define the default value for the parameters like below:



                                    [Route("method")]
                                    public string Get(string a = "", string b = "", string c = "")

                                    return "ok";






                                    share|improve this answer













                                    I think this problem has been solved in some releases of MVC4 and you should define the default value for the parameters like below:



                                    [Route("method")]
                                    public string Get(string a = "", string b = "", string c = "")

                                    return "ok";







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Mar 28 at 7:31









                                    Navid RshNavid Rsh

                                    1495 bronze badges




                                    1495 bronze badges































                                        draft saved

                                        draft discarded















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392141%2fget-string-with-multiple-parameters-in-api-controller-and-parse-it%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                        Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                        Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript