I am trying to easily display errors in my view from anywhere in my code using:
@Html.ValidationSummary("", new { @class = "text-danger" })
Before MVC, I used:
ValidationError.Display("My error message");
And my ValidationError class is as follows:
public class ValidationError : IValidator { private ValidationError(string message) { ErrorMessage = message; IsValid = false; } public string ErrorMessage { get; set; } public bool IsValid { get; set; } public void Validate() {
Now with MVC, to add errors, I cannot use currentPage.Validators . I need to use ModelState , but my problem is that I cannot access the ModelState when I am not in the controller . I tried to access the controller or ModelState through the HttpContext , but I did not find a way to do this. Any idea?
ModelState.AddModelError("", "My error message");
source share