I am generating my form elements by looping over a array. So I have a array = ["name", "age"] and I loop over each item and create a textbox with the appropriate name and related data.
Therefore I creating my form element dynamically such that
<input class="input-validation-error text-box single-line" data-val="true" data-val-required="@arr[i] is required" id="@arr[i]" name="@arr[i]" type="text" value="">
<span class="field-validation-error" data-valmsg-for="@arr[i]" data-valmsg-replace="true"></span>
Instead of :
@Html.EditorFor(model => model.age)
@Html.ValidationMessageFor(model => model.age)
However, because of this, the client-side messages are not being generated. It would catch the error in the server-side validation but client-side stop working.
How can I get the client-side message to work while keeping the ability to create the form dynamically, such that in the blew line of codes the model's property-name can be provided dynamically? Is there a way?
@Html.EditorFor(model => model[@arr[i]])
@Html.ValidationMessageFor(model => model[@arr[i]])
I know that above code doesn't work but its just to emphasize what I am looking for in a solution.
