无法访问视图模型中的对象属性

 lovely蓝衣13 发布于 2023-02-12 19:23

我添加了以下两个模型视图类:

public class AssetCount
    {
        public int CustomerCount { get; set; }
        public int DataCenterCount { get; set; }
        public int FirewallCount { get; set; }
        public int RouterCount { get; set; }
        public int VirtualMachineCount { get; set; }
        public int ServerCount { get; set; }
        public int StorageDeviceCount { get; set; }
        public int RackCount { get; set; }
        public int SwitchCount { get; set; }
        public int CustomCount { get; set; }
    }


public class SystemInformation
    {

        public AssetCount AssetCount { get; set; }
        public ICollection TechnologyAudit { get; set; }
        public ICollection AdminAudit { get; set; }
        public ICollection LatestTechnology { get; set; }
    }

但是,在我的模型类方法中,我无法访问AssetCount对象的属性,例如:

public SystemInformation GetSystemInfo(int pagesize) 

        {
            SystemInformation s = new SystemInformation()
            {
                AssetCount.CustomerCount = entities.AccountDefinitions.Count() //I can not access the CustomerCount !!!!

所以有人可以告诉我这是什么问题吗?谢谢.

1 个回答
  • 您必须首先初始化AssetCount属性:

    SystemInformation s = new SystemInformation()
    {
        AssetCount = new AssetCount { CustomerCount = entities.AccountDefinitions.Count() }
    };
    

    2023-02-12 19:25 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有