验证所需的 MVC3 hidefor() 字段
我正在尝试验证从外部 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>
表单未成功保存,表明已成功需要该属性,但错误消息从未在属性的验证消息中显示
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论