简体   繁体   English

ASPNET 5 MVC 6中的远程验证

[英]Remote Validation in ASPNET 5 MVC 6

Can not find JsonRequestBehavior in aspnet 5 在aspnet 5中找不到JsonRequestBehavior

I am trying to implement remote validation demo and it seem like Microsoft.AspNet.Mvc does not contain JsonRequestBehavior enumeration. 我正在尝试实现远程验证演示,似乎Microsoft.AspNet.Mvc不包含JsonRequestBehavior枚举。 But it does exist in System.Web.Mvc namespace in previous version of MVC 但它确实存在于以前版本的MVC中的System.Web.Mvc命名空间中

Model: 模型:

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; }

View: 视图:

...
<input asp-for="FirstMidName"/>
<span asp-validation-for="FirstMidName"></span>
...

Controller: 控制器:

[HttpGet]
public JsonResult IsAllowedName(string FirstMidName)
{
    if (FirstMidName.ToLower() == "oleg")
    {
        return Json(false, JsonRequestBehavior.AllowGet); 
    }
    return Json(true);
}

Terminal output: 终端输出:

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.

In ASP.NET Core RC1, [Remote] attribute is in the Microsoft.AspNet.Mvc namespace. 在ASP.NET Core RC1中,[Remote]属性位于Microsoft.AspNet.Mvc命名空间中。 In ASP.NET Core RC2, [Remote] attribute is in the Microsoft.AspNetCore.Mvc namespace, I believe. 在ASP.NET Core RC2中,我相信[Remote]属性位于Microsoft.AspNetCore.Mvc命名空间中。

using Microsoft.AspNet.Mvc;

[Remote("IsAllowedName", "Validation", ErrorMessage="This name is not allowed!" )]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM