0

当我使用 JSON 将我的类的数据呈现到网页时,我的类名被呈现为全名,包括完整的命名空间 在 C# 中使用属性的方式是什么,我可以为类名提供一些别名。

我不想公开类的完整名称,例如 {"mycompany.productname.classname":"somevalue"}

我想把它渲染成 {"classname":"somevalue"}

下面是 Receivings.aspx.cs 的代码 //Contains Interaction logic for Receivings.aspx

   public partial class Receivings : Page
    {                
        [WebMethod(EnableSession = true)]
    public static object GetReceivingDetails(int pId)
    {
        try
        {
            RecDetail recDetail = new AccountsBL().GetReceivingDetails(pId);

            //Return result to jTable
            return new { Result = "OK", Records = recDetail };
        }
        catch (Exception ex)
        {
            return new { Result = "ERROR", Message = ex.Message };
        }
    }
}

呈现的 JSON 如下所示

在此处输入图像描述

这是上面截图所示的 JSOn

{"d":{"Result":"OK","Records":{"__type":"ERP.Models.Accounts.RecDetail","Id":0,"Mode":0,"Amount":0,"CatId":0,"CatTypeId":0,"RecId":0,"PayerId":0,"Cash":{"Id":1,"Thousand":30,"FiveHundred":0,"Hundred":0,"Fifty":0,"Twenty":0,"Ten":0,"Five":0,"Two":0,"One":0,"RecId":0,"PayerId":0,"CashRec":30000,"Notes":"xccxvcxcvzc"},"Cheque":{"Id":5,"Bank":"HDFC","Branch":"6868","No":"452326424","Date":"5/5/2013 12:00:00 AM","Amount":10000,"RecId":0,"PayerId":0,"Notes":"asdfasdfasdf"},"DD":{"Id":1,"Bank":"SBI","Branch":"354356","No":"141234123","Date":"5/5/2013 12:00:00 AM","Amount":10000,"RecId":0,"PayerId":0,"Notes":"sdfgsfdgsdfg"}}}}

下面是 RecDetail 类

namespace ERP.Models.Accounts
{
    [ERPAttributes("RecDetail")]
    public class RecDetail
    {
        public int Id { get; set; }

        public byte Mode { get; set; }

        public int Amount { get; set; }

        public byte CatId { get; set; }

        public byte CatTypeId { get; set; }

        public int RecId { get; set; }

        public int PayerId { get; set; }

        public Cash Cash { get; set; }

        public Cheque Cheque { get; set; }

        public DD DD { get; set; }
    }
}
4

0 回答 0