c# – ASPNET 5 MVC 6中的远程验证
发布时间:2020-12-15 22:22:19 所属栏目:百科 来源:网络整理
导读:在aspnet 5中找不到JsonRequestBehavior 我正在尝试实现远程验证演示,似乎Microsoft.AspNet.Mvc不包含JsonRequestBehavior枚举. 但它确实存在于以前版本的MVC中的System.Web.Mvc命名空间中 模型: public class Person : Entity { [Required] [StringLength(
在aspnet 5中找不到JsonRequestBehavior
我正在尝试实现远程验证演示,似乎Microsoft.AspNet.Mvc不包含JsonRequestBehavior枚举. 模型: public class Person : Entity { [Required] [StringLength(512)] [Remote("IsAllowedName","Validation",ErrorMessage="This name is not allowed!" )] [Display(Name = "First (and middle) name")] public String FirstMidName { get; set; } 视图: ... <input asp-for="FirstMidName"/> <span asp-validation-for="FirstMidName"></span> ... 控制器: [HttpGet] public JsonResult IsAllowedName(string FirstMidName) { if (FirstMidName.ToLower() == "oleg") { return Json(false,JsonRequestBehavior.AllowGet); } return Json(true); } 终端输出: MacBook-Air-Anton:labefmvc antonprudkoglyad$dnu build ... /Users/antonprudkoglyad/Projects/LabEFMVC/LabEFMVC/Controllers/ ValidationController.cs(20,24): DNXCore,Version=v5.0 error CS0103: The name 'JsonRequestBehavior' does not exist in the current context Build failed. 解决方法
在ASP.NET Core RC1中,[Remote]属性位于Microsoft.AspNet.Mvc命名空间中.
在ASP.NET Core RC2中,我相信[Remote]属性位于Microsoft.AspNetCore.Mvc命名空间中. using Microsoft.AspNet.Mvc; [Remote("IsAllowedName",ErrorMessage="This name is not allowed!" )] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |