robert.laszlo
robert.laszlo

Reputation: 31

URL not found when trying to make a request

I tried to make a post request in Postman to the server(WebApi) to save an item.

This is the error message

{ "Message": "No HTTP resource was found that matches the request URI 'http://localhost:63924/api/user/save'.", "MessageDetail": "No type was found that matches the controller named 'user'." }

This is the request url:

http://localhost:63924/api/user/save

The body:

{ "Email": "[email protected]", "Password": "1234", "FirstName": "Sue", "LastName": "Smith", "Id": 4, "IsDeleted": false },

The controller :

 public class UserController : Controller
{
    private IService<UserDTO> service;

    public UserController(IService<UserDTO> _service)
    {
        this.service = _service;
    }
    // GET: User
    public ActionResult Index()
    {
        return View();
    }
    [HttpPost]
    [Route("api/user/save")]                      //HERE IS THE ROUTE
    public void AddUser(UserDTO userDTO)
    {
        service.Add(userDTO);
    }
}

Why the URL can't be found?

Upvotes: 0

Views: 460

Answers (1)

awais
awais

Reputation: 515

Change you route to simply "save", because of Web API default route is ..api/{contollername}


    [HttpPost]
    [Route("save")]
    public void AddUser(UserDTO userDTO)
    {
      service.Add(userDTO);
    }

Upvotes: 2

Related Questions