0

I'm developing an ASP.Net core web application and I would like to implements client-side data validation. Is it possible to trigger the asp-validation-for tag helper behavior manually from javascript to show the validation error ? In addition, when I'm returning a view with a Model with errors in ModelState, the span doesn't display error the same way as when the input for Something is empty ( normal way and kendo display). How can I uniformized the display for validation ?

[Required]
public string Something { get; set; }
<span asp-validation-for="Something " class="text-danger"></span>

Edit: I ommit to refer to jquery.validate.min.js and query.validate.unobtrusive.min.js. Moreover, I had problems with validation from dynamic added elements to the DOMS via ajax request (as in jquery-client-side-validation-not-working).

For the second part, I have two different types of validation display (one for (Required attribute) and another one for (Remote attribute). How can I always display the required validation display ?

Here is some code from my ViewModel:

 [Required] 
 [Remote(action: "CheckSomething", controller: "ControllerName")]
 public string Something { get; set; }

Here is some code from my View:

@(Html.Kendo().TextBoxFor(model => model.Something ).HtmlAttributes(new { style = "width: 100%" }))
<span asp-validation-for="Something " class="text-danger"></span>
Ewean
  • 50
  • 1
  • 1
  • 11
  • I’m not sure what you mean by `manual validate`, is it verified on the client through the submit button? You can achieve the client validation by referring to `jquery.validate.min.js` and `jquery.validate.unobtrusive.min.js` , you can refer to this video: https://www.youtube.com/watch?v=PUX3PzyBofg . As for the second question, we need you to provide more detailed code to know the specific reason. – LouraQ May 24 '20 at 07:23
  • Thank you for your comment. It helps me to find why my validation didn't work properly in the client side. I ommit to refer to jquery.validate.min.js and jquery.validate.unobtrusive.min.js. Moreover, I had problems with validation from dynamic added elements to the DOMS via ajax request (as in [link](https://stackoverflow.com/questions/14134949/jquery-client-side-validation-not-working-in-mvc3-partial-view/14135013#14135013)). For the second part of the question, I will edit my code my question to add infos about it – Ewean May 24 '20 at 19:06

0 Answers0