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;
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
add a comment |
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
add a comment |
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
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
c# parsing controller get
asked Mar 28 at 7:24
DavidDavid
1,8637 gold badges37 silver badges71 bronze badges
1,8637 gold badges37 silver badges71 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
You can make it a optional parameter like
[Route("method")]
public string Get(string a, string b, string c = "")
return "ok";
add a comment |
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";
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
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
add a comment |
add a comment |
You can make it a optional parameter like
[Route("method")]
public string Get(string a, string b, string c = "")
return "ok";
add a comment |
You can make it a optional parameter like
[Route("method")]
public string Get(string a, string b, string c = "")
return "ok";
add a comment |
You can make it a optional parameter like
[Route("method")]
public string Get(string a, string b, string c = "")
return "ok";
You can make it a optional parameter like
[Route("method")]
public string Get(string a, string b, string c = "")
return "ok";
answered Mar 28 at 7:30
RahulRahul
65.1k12 gold badges48 silver badges87 bronze badges
65.1k12 gold badges48 silver badges87 bronze badges
add a comment |
add a comment |
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";
add a comment |
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";
add a comment |
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";
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";
answered Mar 28 at 7:31
Navid RshNavid Rsh
1495 bronze badges
1495 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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