我了解使用内置功能来呈现 UI 控件,例如
@Html.TextBoxFor(model => model.CustomerId)
@Html.ValidationMessageFor(model => model.CustomerId)
呈现的 Html 看起来像
<input data-val="true" data-val-number="The field CustomerId must be a number." data-val-required="The CustomerId field is required." id="CustomerId" name="CustomerId" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="CustomerId" data-valmsg-replace="true"></span>
输入元素内的所有属性都用于支持不显眼的验证功能。
但由于某种原因,我无法使用 Html 帮助器进行渲染,但我必须手动编写 Html 标记,例如
<select id="MyId" name="MyId" />
<%=Html.ValidationMessageFor(model => model.MyId)%>
在这种情况下,如何在没有硬编码 select 元素中的所有这些属性的情况下制作不显眼的验证词?
谢谢
哈代