首页 > 解决方案 > 如何从jquery中的以下json字符串中提取确切日期

问题描述

public class Plans
    {
        public long PlanID { get; set; }

        public long? CompanyID { get; set; }

        public string PlanType { get; set; }

        public string PlanName { get; set; }        

        public bool? IsActive { get; set; }

        public int? CreatedBy { get; set; }

        public DateTime? CreatedDate { get; set; }       

        public int? CheckedBy { get; set; }            
    }              

    var date = [{
          0:
            BusinessType: "null"
            CheckedBy: null
            CheckedDate: null
            CompanyID: null
            CompanyName: "Swastik"
            CreatedBy: null
            CreatedDate: "/Date(1587383258707)/"    
        }];

从视图中添加了控制器方法和 ajax 调用以获得更好的帮助。无法找到执行此操作的方法。我无法找出如何从上面在 jquery 中检索到的 json 字符串中提取日期。请协助我。在我正在使用的上面添加了我的模型类。我只是通过调用一个过程并使用 ajax 调用从控制器呈现数据以查看并在控件中填充 ajax 调用成功数据来获取数据。

标签: jqueryasp.net-mvc

解决方案


另一种方法,我所做的是在我的模型中创建另一个属性/函数。

你在asp中的模型

    public class YourModel{
       public DateTime CreatedDate {get;set;}
        // if you want through model
        public string FormattedCreatedDate {get { return CreatedDate.ToString("dd-MM-yyyy");}} 
        // or through functions
        public string GetFormattedCreatedDate(){
            return CreatedDate.ToString("dd-MM-yyyy");
        }
    }

推荐阅读