ASPNET 5 MVC 6 中的远程验证

2024-03-29

在 aspnet 5 中找不到 JsonRequestBehavior

我正在尝试实现远程验证演示,但 Microsoft.AspNet.Mvc 似乎不包含 JsonRequestBehavior 枚举。 但在以前版本的 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>
...

控制器:

[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] 属性位于微软.AspNet.Mvc命名空间。 在 ASP.NET Core RC2 中,[Remote] 属性位于微软.AspNetCore.Mvc命名空间,我相信。

using Microsoft.AspNet.Mvc;

[Remote("IsAllowedName", "Validation", ErrorMessage="This name is not allowed!" )]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASPNET 5 MVC 6 中的远程验证 的相关文章

随机推荐