Answer the question
In order to leave comments, you need to log in
How to solve the problem, does not see the controller method?
send a post request from the view to the controller method ValuesController
[AllowAnonymous]
[Route("api/values/PostClientIdInController")]
public string PostClientIdInController(Clients client)
{
if (_repository.CheckPasswordClient(client.Email, client.password))
{
IDClient = context.Clients.Where(s => s.Email == client.Email).Select(s => s.ID).First();
if (_repository.SetIDUser(client.Email))
return "You have authenticated";
return "Failed";
}
return "Invalid password or such user does not exist";
And here is the Post request
$('#submitLogin').click(function (e) {
e.preventDefault();
debugger;
var client = {
email: $('#emaillogin').val(),
password: $(' #passwordLogin').val()
}
$.ajax({
type: 'POST',
url: '/api/values/PostClientIdInController',
contentType: 'application/json',
data: JSON.stringify(client)
}). success(function (data) {
alert("User id sent");
}).fail(function (data) {
alert("An error occurred while sending the user id");
});
}) Resulting
in this error:
Could not find an HTTP resource matching the request URI " localhost:17224/api/values/PostClientIdInController ".
An action matching the request could not be found on controller 'Values'.
Answer the question
In order to leave comments, you need to log in
Why are you duplicating questions?
Follow the link localhost:17224/api/values/PostClientIdInController just in the browser line. If you get into your controller, then it simply considers your method as Get. Set the [HttpPost] attribute above the method and you will be happy.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question