I am having an issue with the asp-validation-for on a span element in the code below.
<div class="form-group">
@if (Model.Property.Options.ElementAt(i).OptionTypeId == PropertyOptionType.CheckBox)
{
var ItemChecked = (Model.Property.Options.ElementAt(i).OptionValue == "on") ? " checked" : "";
<text><input type="checkbox" class="form-check-input" name="Options[@i].Code" id="Options[@i].Code" @ItemChecked data-val="false" />
<label class="form-check-label" for="Options[@i].Value"> @(Model.Property.Options.ElementAt(i).OptionValue)</label></text>
}
else if (Model.Property.Options.ElementAt(i).OptionTypeId == PropertyOptionType.List)
{
<label class="control-label">
@Model.Property.Options.ElementAt(i).OptionValue
</label>
<select class="form-control" name="Options[@i].Code"></select>
}
<span class="text-danger field-validation-valid" data-valmsg-replace="true" data-valmsg-for="Options.@(i).Code"></span>
When it is rendered in HTML it comes out as
<span class="text-danger field-validation-valid" data-valmsg-replace="true" data-valmsg-for="Options.[3].Code"></span>
But no validation error messages ever land in the span. They are picked up in a page level validation summary when set to all so the unobtrusive code is all working correctly but the ID of the span is being broken by the square brackets.
Any ideas? Thanks Mark