c# – ASPNET 5 MVC 6中的远程验证

在aspnet 5中找不到JsonRequestBehavior

我正在尝试实现远程验证演示,似乎Microsoft.AspNet.Mvc不包含JsonRequestBehavior枚举.
但它确实存在于以前版本的MVC中的System.Web.Mvc命名空间中

模型:

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", "Validation", ErrorMessage="This name is not allowed!" )]
点赞