I have this code:
@this.Html.DropDownListFor(vm => vm.FishId,
new SelectList(this.Model.Fishies, "FishId", "FishName", this.Model.FishId), "Please Select a Fish")
@this.Html.ValidationMessageFor(vm => vm.FishId)
The model for this is simply
public int FishId
{
get;
set;
}
So there is no validation here. When I press submit, I get a message saying The FishId Field is Required.
. This is a client-side validation error. Any idea what's causing this?
If I change the validation message for, to this:
@this.Html.ValidationMessageFor(vm => vm.FishId, "Gotta select a fish, man")
Then the error message changes (which is what I want) to the right of the dropdown, however the validation summary still displays the original message.
All of my other stuff I put validation and messages either as RequiredField(...) attributes, or in a custom validation method.
What's going on, how can I change the validation summary message?
Try put the int to nullable
public int? FishId { get; set; }
It should pass validation because you allow null values
Not sure if you want to disable the validation or change the error message. If the latter, then you should try adding the below to your model.
[Required(ErrorMessage="Gotta select a fish, man")]
public int FishId {get;set;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With