自动构建表单

方式一:通过类构建

  1. 第一步定义类
     /// <summary>
        /// 链接
        /// </summary>
        public class Link : WidgetBase {
            /// <summary>
            /// 链接名称
            /// </summary>
            [Display(Name = "链接名称")]
            [Field(ListShow = true, EditShow = true, ControlsType = ControlsType.TextBox)]
            [Required(ErrorMessage = "链接名称不能为空")]
            [StringLength(20, ErrorMessage = "链接名称不能操作20个字符")]
            public string Name { get; set; }
            /// <summary>
            /// 链接URL
            /// </summary>
            [Display(Name = "URL")]
            [Field(ListShow = true, EditShow = true, ControlsType = ControlsType.TextBox)]
            [Required(ErrorMessage = "链接不能为空")]
            public string Url { get; set; }
            /// <summary>
            /// 图标
            /// </summary>
            [Display(Name = "图标")]
            [Field(ListShow = false, EditShow = true, ControlsType = ControlsType.TextBox)]
            public string Icon { get; set; }
            /// <summary>
            /// 打开方式
            /// </summary>
            /// 
            [Display(Name = "打开方式")]
            [Field(ListShow = true, EditShow = true, ControlsType = ControlsType.DropdownList, DataSource = "ZKCloud.Core.Theme.Domain.Enums.Target")]
            public Target Target { get; set; }
            /// <summary>
            /// 链接字体颜色
            /// </summary>
            [Display(Name = "颜色")]
            [Field(ListShow = false, EditShow = true, ControlsType = ControlsType.Color)]
            public string Color { get; set; } = "#666666";
            /// <summary>
            /// 链接标题
            /// </summary>
            [Display(Name = "链接标题")]
            [Field(ListShow = false, EditShow = true, ControlsType = ControlsType.TextBox)]
            public string Title { get; set; }
    
         
        }
    }
    View Code
  2. 在cshtml文件中设置 ViewData["propertys"]
      Type t = Type.GetType(ViewData["Type"].ToString());
        ClassPropertyAttribute typeclassProperty = t.GetTypeInfo().GetCustomAttribute<ClassPropertyAttribute>();
    
        ClassDescription configDescription = new ClassDescription(t);
        var propertys = configDescription.Propertys.Where(r => r.PropertyAttribute.EditShow == true);

  3. 引用ClassControl
    ViewData["propertys"] = propertys;
    @await Html.AdminWidget("Core", "Common/ClassControl", ViewData)

     


 

 

方式二:通过数据库DataField构建

转载于:https://www.cnblogs.com/zkcloud/p/5662299.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值