Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:58:50+00:00 2026-06-08T23:58:50+00:00

UPDATE My original assumption was that optional parameters were the cause of the problem.

  • 0

UPDATE

My original assumption was that optional parameters were the cause of the problem. That appears to be incorrect. Instead, it appears to be a problem with multiple action methods when one of those methods contains nullable value types (e.g. int? ) for some of the parameters.

I’m using Visual Studio 2012 RC and am just getting started with Web API. I’ve run into an issue and getting the error “No action was found on the controller ‘Bars’ that matches the request.”

I’ve got a Bars controller. It has a Get() method that takes in optional parameters.

public IEnumerable<string> Get(string h, string w = "defaultWorld", int? z=null)
{
    if (z != 0)
        return new string[] { h, w, "this is z: " + z.ToString() };
    else
       return new string[] { h, w };
}

So, I test it out with the following urls

  • /api/bars?h=hello
  • /api/bars?h=hello&w=world
  • /api/bars?h=hello&w=world&z=15

And it works for all three.

Then, I go to add another Get() method, this time with a single id parameter

 public string Get(int id)
 {
     return "value";
 }

I test the urls again. This time /api/bars?h=hello&w=world and api/bars?h=hello fail. The error message is “No action was found on the controller ‘Bar’ that matches the request.”

For some reason, these two methods don’t play nicely together. If I remove Get(int id), it works. If I change int? z to string z, then it works (, but then it requires converting the objects inside my action method!).

Why is Web API doing this? Is this a bug or by design?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:58:52+00:00Added an answer on June 8, 2026 at 11:58 pm

    Problem solved, although, it leaves an additional question. The problem appears to be that the overloaded Action methods are having problems with the optional parameters.

    So the new question is why so, but I will leave that up to lower level guys than me 😉

    But this is good news. I didn’t like the problem you reported, and going the complex type route, while nice to know, is simply a jerry rig fix and would reflect very poorly on how something is working in the Web Api. So the good news is, if you have this problem, it is solved by simply doing away with the optional params, do the good ol’ overloads route. Good news, as this is by no means a jerry rig fix, simply makes you loose a little optional parameter convenience:

    public class BarsController : ApiController
    {
        public string Get(int id)
        {
            return "value";
        }
    
        public IEnumerable<string> Get(string h)
        {
            return Get(h, null, null);
        }
    
        public IEnumerable<string> Get(string h, string w)
        {
            return Get(h, w, null);
        }
    
        public IEnumerable<string> Get(string h, string w, int? z) 
        {
            if (z != 0)
                return new string[] { h, w, "this is z: " + z.ToString() };
            else
                return new string[] { h, w };
        }
    }
    

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: I should have mentioned in the original post that I want to learn
What is the trick that some apps after update keep original data saved before
Update 7/17 SOLVED I've updated my code to the Solved version. Original Question I'm
UPDATE: This question is out of date, but left for informational purposes. Original Question
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
UPDATE UPI_ATTRIBUTE SET SITE_INC ='0' WHERE USER_PROFILING_NAME IN ('CAR_IMPLICIT','CAR_EXPLICIT') Above is my query that
UPDATE : My original question wasn't quite clear. I'm looking for the name of
original (update follows) I'm working with a lot of anonymous functions, ie functions declared
UPDATE : My original question was invalid because I was misreading the MySql logs.
Update: My original intention for this question was to determine if PHP actually has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.