0

I'm a tad confused - I've created an ASP.Net Core Web API MVC Project and testing out a couple of the pre-implemented endpoints but consistently getting the following response "{"id":["The value 'values' is not valid."]}".

target url : https://url/api/values

namespace Project.Api.Controllers
{
    [Route("api)]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }
    }
}

Any ideas? Thanks

5
  • 1
    Which endpoint are you calling? And could you show us just a bit more (relevant) code? The route by default is api/<RouterName> so you might be using an incorrect route. Commented Dec 21, 2018 at 14:45
  • please post the entire controller class as well as the RouteConfig. If you can include an example of the URI you are making a request to as well, that'd be great Commented Dec 21, 2018 at 15:04
  • I've not changed anything outside of the default setup Commented Dec 21, 2018 at 15:07
  • The default project template works so there was either a change to it or you're not making a request to a valid route correctly- please post the relevant code so we can help Commented Dec 21, 2018 at 15:08
  • @GregH Updated the post Commented Dec 21, 2018 at 15:14

1 Answer 1

1

You have the [Route("api")] annotation on your controller so your Get method will be accessible at localhost:port/api instead of localhost:port/api/values.

If you change the annotation to [Route("api/[controller]")] then the current route you are requesting (localhost:port/api/values) will work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.