在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.Model实体 /// <summary> /// 课程编号 /// </summary> [MaxLength(50)] [Remote("IsUnique_Available", "Course")] [Required(ErrorMessageResourceName = "Course_CourseNum", ErrorMessageResourceType = typeof(ErrorMessage))] public string CourseNum { get; set; } 2.CourseController控制器IsUnique_Available验证方法 #region 验证课程编号不唯一 public JsonResult IsUnique_Available(string CourseNum) { Course model = o_Res.GetCourseAny(a => a.CourseNum == CourseNum); if (model == null) { return Json(true, JsonRequestBehavior.AllowGet); } else { string suggestedUID = String.Format(CultureInfo.InvariantCulture, "课程编号:{0} 已经存在!", CourseNum); return Json(suggestedUID, JsonRequestBehavior.AllowGet); } } #endregion 3.cshtml添加页面 <td colspan="3"> @Html.TextBoxFor(a => a.CourseNum, new { maxlength = 50 }) @Html.ValidationMessageFor(model => model.CourseNum) </td> 4.cshtml编辑页面(disabled = true) <td colspan="3"> @Html.TextBoxFor(a => a.CourseNum, new { maxlength = 50 , disabled = true }) @Html.ValidationMessageFor(model => model.CourseNum) </td>
|
请发表评论