首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ASPNET 5 MVC 6中的远程验证

ASPNET 5 MVC 6中的远程验证
EN

Stack Overflow用户
提问于 2015-10-24 18:46:33
回答 1查看 2.5K关注 0票数 4

在aspnet 5中找不到JsonRequestBehavior

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

型号:

代码语言:javascript
运行
复制
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; }

查看:

代码语言:javascript
运行
复制
...
<input asp-for="FirstMidName"/>
<span asp-validation-for="FirstMidName"></span>
...

主计长:

代码语言:javascript
运行
复制
[HttpGet]
public JsonResult IsAllowedName(string FirstMidName)
{
    if (FirstMidName.ToLower() == "oleg")
    {
        return Json(false, JsonRequestBehavior.AllowGet); 
    }
    return Json(true);
}

终端输出:

代码语言:javascript
运行
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2016-04-04 11:07:29

Microsoft.AspNet.Mvc核心RC1中,远程属性位于ASP.NET命名空间中。我相信,在Microsoft.AspNetCore.Mvc核心RC2中,远程属性位于ASP.NET名称空间中。

代码语言:javascript
运行
复制
using Microsoft.AspNet.Mvc;

[Remote("IsAllowedName", "Validation", ErrorMessage="This name is not allowed!" )]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33321996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档