19

I am creating a Web Api (v2.0) Method that needs to take in a decimal value as its parameter.

I am getting a 404 not found error if I use the following URL:

http://localhost:4627/api/Product/Eligibility/10.5

But it works if I use the following URL against an Int parameter:

Http://localhost:4627/api/Product/Eligibility/10

These are the two corresponding Methods in the api:

// GET api/Product/Eligibility/10.0
[Route("api/Product/Eligibility/{amount:decimal}")]
public decimal GetEligibiilty(decimal amount)
{
    return amount;
}

// GET api/Product/Eligibility/10
[Route("api/Product/Eligibility/{amount:int}")]
public decimal GetEligibiilty(int amount)
{
    return amount;
}

Steve

Nkosi
  • 215,613
  • 32
  • 363
  • 426
samneric
  • 2,707
  • 2
  • 24
  • 29

3 Answers3

44

Got it working by adding a "/" to the end of the URL!

http://localhost:4627/api/Product/Eligibility/10.5/

Will find this method:

// GET api/Product/Eligibility/10.5/
[Route("api/Product/Eligibility/{amount:decimal}/")]
public decimal GetEligibiilty(decimal amount)
{
    return amount;
}

Steve

Nkosi
  • 215,613
  • 32
  • 363
  • 426
samneric
  • 2,707
  • 2
  • 24
  • 29
1

Had a similar problem with passing a decimal in the URL, anyone using ASP.NET web pages here is a solution when redirecting after a transaction and the variable amount has a decimal in it:

Response.Redirect(@Href("~/Thankyou", amount + "/"));

The slash at the end of the URL is required to get it working.

Kate Orlova
  • 2,899
  • 5
  • 10
  • 29
Ben
  • 83
  • 8
1

I recently had this problem while working with Web API in Visual Studio 2015. I solved the problem by adding ?parameterName=decimalValue at the end of the URL. In your case could be something similar to this:

http://localhost:4627/api/Product/Eligibility?amount=10.5

I hope can help.

Joseph L.
  • 301
  • 2
  • 6