1

I'm trying to validate email using this remote validation attribute, but I keep getting this error. Does anyone know the exact reason for this?

public class StudentVm
{
       public string Id { get; set; }
       [Required]
       public string Name { get; set; }
       [Remote( "Test", "Validation", HttpMethod = "POST", ErrorMessage = "Invalid Email.")]
       public string Email { get; set; }
}

//The validation controller
[Route("Validation/[action]")]
public class ValidationController : Controller
{
   [HttpPost]
   public async Task<IActionResult> Test(string Email)
   {
       return Json(false);
   }
}

Error

An unhandled exception occurred while processing the request. TypeLoadException: Could not load type 'System.Web.Routing.RouteValueDictionary' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Jackdaw
  • 7,626
  • 5
  • 15
  • 33
  • 1
    change `[Route("Validation/[action]")]` to `[Route("[controller]")]` and change this `[HttpPost]` to `[HttpPost, Route("test")]`. That will give you are route of `/Validation/test` and you would have to post this: `"hello@world.com"` If you want to post the model you have above, then you would have to change `string email` to `[FromBody] StudentVm student` – Andy Nov 08 '20 at 05:37
  • I tried it, but not work for me – Samithra niroshana Nov 08 '20 at 05:59
  • 1
    Could you share your package reference?It seems that you have used wrong package. – Rena Nov 09 '20 at 02:01

0 Answers0