Moving from HtmlHelpers I created a few year ago, I have a custom Taghelper that as is marked up during development as so...
<gdropdown asp-for="Type_ID" asp-items="cboType_SelectOne"></gdropdown>
All works fine and the output for this is as follows...
<div>
<select id="Type_ID" name="Type_ID">
<option value=-1> - Select One - </option>
<option value=9>Aux. Ext. Device</option>
<option value=28>Backup Device</option>
...
</select>
</div>
Now I am looking for help crafting my OWN validation SPAN to add to the output as follows...
<div>
<select id="Type_ID" name="Type_ID">
<option value=-1> - Select One - </option>
<option value=9>Aux. Ext. Device</option>
<option value=28>Backup Device</option>
...
</select>
<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="Type_ID">
<span for="Type_ID">Req!</span>
</span>
</div>
Anyway, I can manage to do the basics of creating that SPAN, however I can't get to the data annotations for the field that is being added/edited.
Using HtmlHelpers I could use htmlHelper.ValidationMessageFor() as follows in order to craft the output automatically...
public static MvcHtmlString CustomLookupFor2<TModel, TValue>(this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TValue>> exp, string url, bool includeValidation, object options)
{
...
if (includeValidation) sbCtrls.Append(htmlHelper.ValidationMessageFor(expression));
...
}
From within the TagHelper ProcessAsync method, how can I get to the same or similar data annotation information? Or better still, how can I auto generate the validation element entirely in in a similar fashion as above?