0

I have simple form with get request, but jquery validate unobtrusive does not generate HTML for validation message.
I don't know what is wrong =(

Razor:

<form class="input-form" action="someUrl" method="get">
   @Html.ValidationSummary(true)

   @for (var i = 0; i < 2; i++)
   {
      @{
        var newId = Guid.NewGuid();
      }

       @Html.TextBoxFor(m => m.Value, new { @class = "input-item", id = newId })
       @Html.ValidationMessageFor(m => m.Value, "message", new { @class = "error", id = newId})
   }

    <button class="submit-button" type="submit">Submit</button>
</form>


<form class="input-form" action="someUrl" method="get" novalidate="novalidate">
   <input class="input-item" id="Value" name="Value" id="fcacdcb4-02fb-4701-8b8a-a0aa1d5799ae" type="text" value="0">
   <input class="input-item" id="Value" name="Value" id="590afe32-3266-497d-ad3b-b1f9939540ef" type="text" value="0">
   <button class="submit-button" type="submit">Submit</button>
</form>


There are not elements with validation message.

I have this Model in C#:

    public class InputViewModel
    {
        public HtmlString Description { get; set; }

        public string Alias { get; set; }

        [Required]
        public int Value { get; set; }

        public string Label { get; set; }
    }
}


I also have the necessary scripts in the parent view:

<script src="jquery.js"></script>
<script src="JQuery/jquery.validate.min.js"></script>
<script src="JQuery/jquery.validate.unobtrusive.min.js"></script>


I don't know what I missed.

UPD: Unfortunately I can not show the production code, but it is almost the same as in the question.
I still can’t understand what I'm doing wrong and why there is no validation div in the result HTML.=(
Can you tell me more options for validating fields on the client?

Slava Podolskiy
  • 155
  • 1
  • 11
  • You're rendering inputs with same ID, each HTML element should have Unique ID, you have to fix this first, and take a look at this post https://stackoverflow.com/questions/8635406/html-validationsummarytrue-whats-the-true-do – pim3nt3l Dec 16 '19 at 15:32
  • I fixed id, but nothing happened (see update in question) – Slava Podolskiy Dec 16 '19 at 15:58
  • Is there any way to see full code? I tested it and work for me (and the validation works for first input) – pim3nt3l Dec 16 '19 at 18:09
  • Unfortunately I can not show the production code, but it is almost the same as in the question. I still can’t understand what I'm doing wrong and why there is no validation div in the result HTML. =( Can you tell me more options for validating fields on the client? – Slava Podolskiy Dec 17 '19 at 12:48

0 Answers0