簡體   English   中英

ASPNET 5 MVC 6中的遠程驗證

[英]Remote Validation in 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!" )]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM