VC5 project
I have this TextBox and Validation message in my Razor view:
@Html.TextBoxFor(m => m.FireSrv.Size) @Html.ValidationMessageFor(m => m.FireSrv.Size)
I want to clear (not hide) just this message, I do not want to clear the entire form.
I tried this and it doesn't work:
$('#FireSrv_Size').find(".field-validation-valid").remove();
FireSrv_Size is correct, it is the id of the field in the form.
I've implemented
IValidatableObject
in my ViewModel.
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
string em = "Size is required";
if (HasFireSrv) { if (string.IsNullOrEmpty(FireSrv.Size)) { yield return new ValidationResult(em, new[] { "FireSrv.Size" }); } }
...
This is what is shown in View source before and after generating the validation error:
<input id="FireSrv_Size" name="FireSrv.Size" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="FireSrv.Size" data-valmsg-replace="true"></span>
<input class="input-validation-error" id="FireSrv_Size" name="FireSrv.Size" type="text" value="" />
<span class="field-validation-error" data-valmsg-for="FireSrv.Size" data-valmsg-replace="true">Size is required</span>
How can I clear just that one validation message?