fokwabest
Member
- Joined
- Aug 18, 2023
- Messages
- 7
- Programming Experience
- 5-10
I am new to asp.net core. I have a form which is generated dynamically. I want the validation error message to be "The value must be numeric" instead I get
"The value 'a' is invalid" when I submit the form.
Here is my View Model:
Here is my form code:
Despite the fact, I have put the custom error message in my View Model as shown above, I keep getting the default message "The value '' is invalid". Please what is the solution to this kind of scenario ?
"The value 'a' is invalid" when I submit the form.
Here is my View Model:
C#:
[RegularExpression("^[0-9]*$", ErrorMessage = "The value must be numeric")]
public List<int> Units_Service { get; set; }
Here is my form code:
C#:
for (int i = 0; i < Model.Workload_Category_Name.Count; i++)
{
<div class="row">
<div class="col-md-3">
<b><u> @Html.DisplayFor(model => model.Workload_Category_Name[i])</u> </b>
</div>
<div class="col-md-4">
@Html.TextBoxFor(model => model.Units_Service[i], new { style = "width: 15%", MaskedTextBox = "9999" })
@Html.ValidationMessageFor(model => model.Units_Service[i])
</div>
</div>
}
Despite the fact, I have put the custom error message in my View Model as shown above, I keep getting the default message "The value '' is invalid". Please what is the solution to this kind of scenario ?