I have a model which looks like this:
public class ChartModel
{
public List<int> GoalList { get; set; } = new List<int>();
public List<string?> LabelList { get; set; } = new List<string?>();
[Required]
[StringLength(maximumLength: 75)]
public string? LabelValidation { get; set; }
[DefaultSettingValue("0")]
[Range(1, 100)]
public int GoalValidation { get; set; }
}
I want the attributes above each List to apply to the int and string types, respectively, inside them. Seeing that just doing something like:
[Required]
[StringLength(maximumLength: 75)]
public List<string?> LabelList { get; set; } = new List<string?>();
doesn't work, I made the LabelValidation and GoalValidation variables with the intention of using them in an HTML form where the user inputs values for labels and goals into the list like so:
<input asp-for="LabelList[ind]" class="form-control" placeholder="@ViewBag.Chart.LabelList[ind]" value="@ViewBag.Chart.LabelList[ind]" />
<span asp-validation-for="LabelValidation" class="text-danger"></span>
<input asp-for="GoalList[ind]" class="form-control" placeholder="@ViewBag.Chart.GoalList[ind]" value="@ViewBag.Chart.GoalList[ind]" />
<span asp-validation-for="GoalValidation" class="text-danger"></span>
but that does not seem to work either. How can I apply these attributes to the elements within the lists?