M
M
Maxim Akhmerov2018-04-25 20:58:08
ASP.NET
Maxim Akhmerov, 2018-04-25 20:58:08

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

2 answer(s)
E
eRKa, 2018-04-25
@kttotto

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.

A
Artem, 2018-04-25
@devspec

If I'm not mistaken, this thing needs to be updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question