Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Asp.net Core Data Annotations failing to decorated multiples of the same model type.

$
0
0

I'm using a partial view to create a security question and answer view using a model. Besides the issue of naming each one with a index number. That is a whole seperate issue all together.
I want 3 security questions and answers. I add the partial view 3 times to create 3 security questions and answers. Of those 3 only the the first security question and answer is decorated with
model requirements. The next 2 is missing the model requirements. I decided this is a [BUG]. At some point the web controls get decorated with the model requirements. For some reason it only does one
and ignores the reset.

What is going on here and why is this not working failing

Model:

public class QNAViewModel
{
     [Required(ErrorMessage = "The question field is required")]
     public String Question { get; set;}

     [Required(ErrorMessage = "The answer field is required")]
     [StringLength(250, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 3)]
     public String Answer { get; set; }

}

Partial View:

@model MyNameSpace.Models.ProfileViewModels.QNAViewModel
@{
    string qId = String.Format("Question{0}", ViewData["Index"]);
    string aId = String.Format("Answer{0}", ViewData["Index"]);
}<div class="form-group"><label asp-for="Question" for="@qId" class="col-md-2 control-label"></label><div class="col-md-5"><select asp-for="Question" id="@qId" name="@qId" class="form-control" asp-type="securityquestion"></select><span asp-validation-for="Question" data-valmsg-for="@qId" class="text-danger"></span></div></div><div class="form-group"><label asp-for="Answer" for="@aId" class="col-md-2 control-label"></label><div class="col-md-5"><input asp-for="Answer" id="@aId" name="@aId" class="form-control" /><span asp-validation-for="Answer" data-valmsg-for="@aId" class="text-danger"></span></div></div>


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>