I have a model that validates that a field is for a URL.
/// <summary>
/// Gets or sets the url of the event.
/// </summary>
[DisplayName("Event URL")]
[Url(ErrorMessage = "URL must be a valid URL.")]
public string EventURL { get; set; }
In addition, I have some custom validation in my model. I validate the model by checking the ModelState.IsValid property and also with:
var validationResults = new List<ValidationResult>();
bool isValid = Validator.TryValidateObject(
model,
new ValidationContext(model, null, null),
validationResults,
false);
I return the view with the model updated and a property SubmissionErrors with the validation results from validating the model. I then return View(model);
In my view I have a validation box that displays when an error occurs. It should display all the validation results and any other errors. I've thrown in @Html.ValidationMessageFor(m => m.EventURL) and @Html.ValidationSummary() with both of them not displaying the error to the user when they submit an invalid URL. I'm not sure what I am doing wrong and I can't seem to locate any reason why this would be occur. Am I utilizing the URL tag incorrectly, or the validation message incorrectly? Any help would be appreciated.