0

我正在使用 ASP.NET WebApi ,在将结果发送到 JSON 时,是否可以在 ModelMetadata 上发送数据注释,例如 DisplayName 属性、 ShowInEdit 、 ShowInDispplay 和其他自定义属性以及 Fieldnmae 和值。

public class Role
    {
        public Role()
        {
            Users = new List<User>();
        }

        [ScafoldingColumn(false)]
        public int RoleId { get; set; }

        [DisplayName("Role Name")]
        [Required]
        [ShowForDisplay(true)]
        [ShowForEdit(true)]
        public string RoleName { get; set; }

        [ShowForDisplay(true)]
        public ICollection<User> Users { get; set; }
    }

提前致谢

4

1 回答 1

0

JSON as a file format doesn't support data annotations. The best solution for that, which I've seen so far, is to have meta actions. Those meta actions can return the data-annotations as an additional json-object. You can afterwards also cache those data in the local storage on the client or similar, so you don't need to download them, every time the user accesses a page.

于 2013-08-12T19:28:16.787 回答