asp.net-mvc – 客户端验证未显示消息
发布时间:2020-12-16 04:00:34 所属栏目:asp.Net 来源:网络整理
导读:我有一个MVC4互联网应用程序,其中包含用于创建用户帐户的表单.表单验证有效,但输入验证失败时,不会显示错误消息.它仍然会阻止提交,直到验证问题得到解决但没有文本 剃刀查看表格 h2Create New Account/h2fieldset legend/legend @using (Html.BeginForm("Cre
我有一个MVC4互联网应用程序,其中包含用于创建用户帐户的表单.表单验证有效,但输入验证失败时,不会显示错误消息.它仍然会阻止提交,直到验证问题得到解决但没有文本
剃刀查看表格 <h2>Create New Account</h2> <fieldset> <legend></legend> @using (Html.BeginForm("CreateUser",null)){ @Html.AntiForgeryToken() <table class="create"> <tr> <td colspan="2"><b>New Account</b> </tr> <tr> <td>@Html.DisplayNameFor(model=>model.UserName)</td><td>@Html.TextBoxFor(model=>model.UserName)</td> <td>@Html.DisplayNameFor(model=>model.EmailAddress)</td><td>@Html.TextBoxFor(model=>model.EmailAddress)</td> <td><input type="submit" value="Create User" /></td> </tr> </table> } </fieldset> @Html.ValidationSummary() 使用的包包括验证文件 bundles.Add(new ScriptBundle("~/bundles/asset").Include( "~/Scripts/jquery-{version}.js","~/Scripts/jquery-ui-{version}.js","~/Scripts/jquery.validate*","~/Scripts/jquery.unobtrusive*")); 使用的模型是一个实体模型,我添加了一个部分类来注释验证要求 [MetadataType(typeof(UserProfileMetadata))] public partial class UserProfile { //Empty Class just required for adding class level attribute } public class UserProfileMetadata { //Fields from user profile requiring annotations [EmailAddress] [Required] [Display(Name = "Email Address")] public string EmailAddress { get; set; } [Required] public string UserName { get; set; } } 验证工作,但现在显示该消息使我认为它必须是标记错误,但我只是看不到它. 解决方法
在表单中移动ValidationSummary将修复它.
<h2>Create New Account</h2> <fieldset> <legend></legend> @using (Html.BeginForm("CreateUser",null)){ @Html.ValidationSummary() @Html.AntiForgeryToken() <table class="create"> <tr> <td colspan="2"><b>New Account</b> </tr> <tr> <td>@Html.DisplayNameFor(model=>model.UserName)</td> <td>@Html.TextBoxFor(model=>model.UserName)</td> <td>@Html.DisplayNameFor(model=>model.EmailAddress)</td><td>@Html.TextBoxFor(model=>model.EmailAddress)</td> <td><input type="submit" value="Create User" /></td> </tr> </table> } </fieldset> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- 详解在Azure上部署Asp.NET Core Web App
- .net – 设置页面标题不起作用
- asp.net-core – ASP.NET 5中RegisterObject / Q
- 如何在ASP.Net 3.5中制作标签,标题和字段标题内容
- 一个通过JSONP跨域调用WCF REST服务的例子(以jQ
- asp.net – Session实际上如何在MVC中运行?
- asp.net-mvc – 如何将通用列表传递给Html.Actio
- .NET Core的文件系统[3]:由PhysicalFileProvide
- asp.net – SSRS与自定义Web UI
- asp.net – 如何在Firefox上命名文件以供下载?
热点阅读