Web API - How to validate the model from Dataannotation.Remote()?

Asked

Viewed 205 times

0

I have the following model (DTO):

public class PessoaAcesso : Pessoa
{
    [Remote("LoginUnico", "Pessoa", ErrorMessage = "Esse Login já existe! Escolha outro.")]
    public virtual string Login { get; set; }
    ...
}

In my Apicontroller (Webapi) I implemented the "Loginunico" method for testing:

public JsonResult<bool> LoginUnico(string login)
{
    return Json(false);
}

But when making the request via POST is not triggering the method. It was for him to reject the insertion of the new person, but is accepting.

Who has already implemented Remote() in the Webapi can guide me.

1 answer

1

Write down your method with [HttpPost]:

[HttpPost]
public JsonResult<bool> LoginUnico(string login)
{
    return Json(false);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.