1

I'm trying to validate a hidden field that is updated from an external jQuery call.

Model:

    [Required(ErrorMessage = "UserId is required")]
    public int? UserId { get; set; }

Master Page:

    <script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery-1.7.min.js") %>'></script>
    <script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery-ui-1.8.16.custom.min.js") %>'></script>
    <script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery.numeric.js") %>'></script>
    <script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery.validate.min.js") %>'></script>
    <script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery.validate.unobtrusive.min.js") %>'></script>
    <script type="text/javascript" src='<%= ResolveUrl("~/Scripts/RangeDateValidator.js") %>'></script>
    <asp:ContentPlaceHolder ID="MainContent" runat="server" />

View:

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm("FormSave", "Form", FormMethod.Post))
       {%>
    <%: Html.ValidationMessageFor(model => model.UserId) %>
    <%: Html.HiddenFor(model => model.UserId) %>
    <p>
        <input type="submit" value="Save" />
    </p>
    <% } %>
    </asp:Content>

The form does not save successfully, indicating that the attribute is being successfully required but the error message never shows in the validationmessage for attribute

neuhoffm
  • 33
  • 1
  • 7
  • possible duplicate of [Perform validation on hidden fields](http://stackoverflow.com/questions/10136342/perform-validation-on-hidden-fields) – Luke Jul 16 '15 at 12:01

0 Answers0