zoukankan      html  css  js  c++  java
  • 自动构建表单

    方式一:通过类构建

    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构建

  • 相关阅读:
    读TIJ -6 类再生
    STM32 外设配置关键步骤-驱动出了问题,最好还是瞧瞧--待续
    oracle 10g 11g rac 虚拟环境切换
    UFLDL教程之(三)PCA and Whitening exercise
    VIM配置文件
    Codeforces 586D Phillip and Trains(DP)
    51Nod 1272最大距离 (树状数组维护前缀最小值)
    Codeforces 482B Interesting Array(线段树区间更新)
    Codechef Chef and Triangles(离散化+区间并集)
    POJ1655 Balancing Act(树的重心)
  • 原文地址:https://www.cnblogs.com/zkcloud/p/5662299.html
Copyright © 2011-2022 走看看