最近在开动科技创新作品的开发,出现了一个让人很烦恼的错误,每次从浏览页跳转到编辑页时就会出现一下错误
非介入式客户端验证规则中的验证类型名称必须唯一。下列验证类型出现重复: required
上一下出错的代码
model
public partial class td_students { [StringLength(12)] [Key] [HiddenInput(DisplayValue = false)] public string Id { get; set; } [Required] [StringLength(10)] [Display(Name = "学号")] public string school_code { get; set; } [Required] [StringLength(10)] [Display(Name = "姓名")] public string student_name { get; set; } [StringLength(10)] [Display(Name = "年级")] public string grade { get; set; } [StringLength(10)] [Display(Name = "院系")] public string dept { get; set; } [StringLength(10)] [Display(Name = "专业")] public string major { get; set; } [StringLength(10)] [Display(Name = "班级")] public string banji { get; set; } [StringLength(2)] [Display(Name = "性别")] public string gender { get; set; } [StringLength(10)] [Display(Name = "民族")] public string nation { get; set; } [Display(Name = "出生日期")] public DateTime? born_date { get; set; } [StringLength(14)] [Display(Name = "手机号码")] public string telephone { get; set; } [StringLength(6)] [Display(Name = "政治面貌")] public string politicstatus { get; set; } [StringLength(18)] [Display(Name = "身份证号码")] public string ID_card { get; set; } [StringLength(20)] [Display(Name = "户籍")] public string native_place { get; set; } [StringLength(100)] [Display(Name = "家庭住址")] public string address { get; set; } [StringLength(14)] [Display(Name = "家庭联系电话")] public string home_telephone { get; set; } [Display(Name = "入学时间")] public DateTime? rollin_date { get; set; } [StringLength(10)] [Display(Name = "宿舍")] public string dormitory { get; set; } [StringLength(50)] [Display(Name = "照片")] public string imageurl { get; set; } public bool? audit { get; set; } [Column("lock")] public bool? _lock { get; set; } }
前端代码:
@using (Html.BeginForm("Edit", "Student", FormMethod.Post, new { enctype = "mutipart/form-data", @class="form-inline" })) { <div class="panel-body"> @Html.Hidden("studentId", Model.Id) @foreach (var property in ViewData.ModelMetadata.Properties) { switch (property.PropertyName) { case "Id": case "audit": case "_lock": case "imageUrl": break; default: <div class="form-group"> <label>@(property.DisplayName ?? property.PropertyName)</label>//这里就抛出异常 @Html.TextBox(property.PropertyName, null, new { @class = "form-control form-inline input-sm" }) @Html.ValidationMessage(property.PropertyName) </div> break; } } </div> }
国内搜索引擎搜索不到任何相关的解决方案 使用google搜索,终于StackOverflow的在不起眼的小角落里找到了解决办法
翻译过来就是因为引入了Ninject.MVC3这个包,出现了注入验证,卸载Ninject重装之后就解决了问题
我的项目中也使用了Ninject来做依赖注入 安装的是Ninject.MVC5这个包 卸载重装之后搞定
真的是揪心啊
这里说一句,遇到问题国内搜索引擎搞不定,就去StackOverflow.com 一般都可以找到解决方案