首页 > 解决方案 > 将远程属性添加到 asp.net 核心时出错

问题描述

当我将[Remote()]属性添加到类属性时,会抛出以下异常:

TypeLoadException:无法从程序集“System.Web,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.Routing.RouteValueDictionary”

using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace Entities
{
    [Serializable]
    public class EmployeeEntity
    {
        public int Id { get; set; }
        
        [Required(ErrorMessage = "Required")]
        [MaxLength(20)]
        [RegularExpression(@"^\S*$", ErrorMessage = "No white space allowed")]
        [Remote("IsUserNameAvailable", "Employee",HttpMethod ="GET", ErrorMessage = "EmailId already exists in database.")]



标签: asp.net-mvcasp.net-core

解决方案


已解决 - 在我安装 Microsoft.AspNetCoreCore.Routing 之后。问题是在 asp 核心项目中使用 System.Web.Mvc


推荐阅读