验证所需的MVC3 hiddenfor()字段

时间:2011-11-23 19:52:28

标签: asp.net-mvc-3 validation hiddenfield

我试图验证从外部jQuery调用更新的隐藏字段。

型号:

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

母版页:

    <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" />

查看:

    <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>

表单未成功保存,表示该属性已成功需要,但错误消息从未显示在属性的验证消息中

0 个答案:

没有答案