BootstrapBlazor 智能生成神器(一)AutoGenerateColumnAttribute 特性介绍
原文连接:https://www.cnblogs.com/ysmc/p/16074645.html
BootstrapBlazor 官网地址:https://www.blazor.zone
介绍
BootstrapBlazor 中的 Table 组件、EditorForm 表单组件、ValidateForm 表单组件 等等组件,都具有根据实体类自动生成相应功能的能力,而这里起到关键作用的就是 AutoGenerateColumnAttribute,从命名可以得知,这是一个特性,让我们来看看他支持哪些功能吧。
| 属性 | 类型 | 作用 | 说明 |
| Order | int | 获得/设置 显示顺序 |
规则如下: >0时排前面,1,2,3... =0时排中间(默认) <0时排后面,...-3,-2,-1 |
| Ignore | bool | 获得/设置 是否忽略 | 默认为 false 不忽略 |
| DefaultSort | bool | 获得/设置 是否为默认排序列 | 默认为 false |
| SkipValidate | bool | 获得/设置 是否不进行验证 | 默认为 false |
| IsReadonlyWhenAdd | bool | 获得/设置 新建时此列只读 | 默认为 false |
| IsReadonlyWhenEdit | bool | 获得/设置 编辑时此列只读 | 默认为 false |
| DefaultSortOrder | SortOrder | 获得/设置 是否为默认排序规则 | 默认为 SortOrder.Unset |
| Width | int | 获得/设置 列宽 | |
| Fixed | bool | 获得/设置 是否固定本列 | 默认 false 不固定 |
| Visible | bool | 获得/设置 列是否显示 | 默认为 true 可见的 |
| CssClass | string? | 获得/设置 列 td 自定义样式 | 默认为 null 未设置 |
| ShownWithBreakPoint | BreakPoint | 获得/设置 显示节点阈值 | 默认值 BreakPoint.None 未设置 |
| FormatString | string? | 格式化字符串 | 如时间类型设置 yyyy-MM-dd |
| PlaceHolder | string? | 获得/设置 placeholder 文本 | 默认为 null |
| Formatter | Func<object?, Task<string>>? | 获得/设置 列格式化回调委托 | |
| HeaderTemplate | RenderFragment<ITableColumn>? | 获得/设置 表头模板 | |
| ComponentType | Type? | 获得/设置 组件类型 | 默认为 null |
| Template | RenderFragment<object>? | 获得/设置 显示模板 | |
| Step | object? | 获得/设置 步长 | 默认为 1 |
| Rows | int | 获得/设置 Textarea 行数 | |
| PropertyType | Type? | 获得 属性类型 | |
| Text | string? | 获得/设置 当前属性显示文字 列头或者标签名称 |
实战
下面我们来看看它在 ValidateForm 组件 与 EditorForm 组件中的表现
实体类 Foo.cs
1 public class Foo
2 {
3 /// <summary>
4 ///
5 /// </summary>
6 [Key]
7 [Display(Name = "主键")]
8 [AutoGenerateColumn(Ignore = true)]
9 public int Id { get; set; }
10
11 /// <summary>
12 ///
13 /// </summary>
14 [Required(ErrorMessage = "{0}不能为空")]
15 [AutoGenerateColumn(Order = 10, Filterable = true, Searchable = true)]
16 [Display(Name = "姓名")]
17 public string? Name { get; set; }
18
19 /// <summary>
20 ///
21 /// </summary>
22 [AutoGenerateColumn(Order = 1, FormatString = "yyyy-MM-dd", Width = 180)]
23 [Display(Name = "日期")]
24 public DateTime? DateTime { get; set; }
25
26 /// <summary>
27 ///
28 /// </summary>
29 [Display(Name = "地址")]
30 [Required(ErrorMessage = "{0}不能为空")]
31 [AutoGenerateColumn(Order = 20, Filterable = true, Searchable = true)]
32 public string? Address { get; set; }
33
34 /// <summary>
35 ///
36 /// </summary>
37 [Display(Name = "数量")]
38 [Required]
39 [AutoGenerateColumn(Order = 40, Sortable = true)]
40 public int Count { get; set; }
41
42 /// <summary>
43 ///
44 /// </summary>
45 [Display(Name = "是/否")]
46 [AutoGenerateColumn(Order = 50)]
47 public bool Complete { get; set; }
48
49 /// <summary>
50 ///
51 /// </summary>
52 [Required(ErrorMessage = "请选择学历")]
53 [Display(Name = "学历")]
54 [AutoGenerateColumn(Order = 60)]
55 public EnumEducation? Education { get; set; }
56
57 /// <summary>
58 ///
59 /// </summary>
60 [Required(ErrorMessage = "请选择一种{0}")]
61 [Display(Name = "爱好")]
62 [AutoGenerateColumn(Order = 70, Editable = false)]
63 public IEnumerable<string> Hobby { get; set; } = new List<string>();
64 }
页面 Foo.razor
1 <ValidateForm Model="@ValidateModel">
2 <EditorForm TModel="Foo">
3 <FieldItems>
4 <EditorItem @bind-Field="@context.DateTime" Readonly="true" />
5 <EditorItem @bind-Field="@context.Hobby" Items="@Hobbys" />
6 </FieldItems>
7 <Buttons>
8 <Button ButtonType="ButtonType.Submit" Icon="fa fa-save" Text='提交' />
9 </Buttons>
10 </EditorForm>
11 </ValidateForm>
呈现效果

同时支持根据实体类属性的特性进行表单验证,非常的好用

BootstrapBlazor 智能生成神器(一)AutoGenerateColumnAttribute 特性介绍的更多相关文章
- Bootstrap Blazor Table 组件(三)智能生成
原文链接:https://www.cnblogs.com/ysmc/p/16201153.html Bootstrap Blazor 官网地址:https://www.blazor.zone 有了解过 ...
- Xcode9新特性介绍-中文篇
背景: Xcode 9 新特性介绍: 1.官方原文介绍链接 2.Xcode9 be ta 2 官方下载链接 本文为官方介绍翻译而来,布局排版等都是按照官方布局来的. 与原文相比,排版上基本还是熟悉的配 ...
- Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性
Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性 Apache hadoop 项目组最新消息,hadoop3.x以后将会调整方案架构,将Mapreduce 基于内存+io+ ...
- jdk7和8的一些新特性介绍
jdk7和8的一些新特性介绍 本文是我学习了解了jdk7和jdk8的一些新特性的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwor ...
- ArcGIS 10.3 for Desktop新特性介绍
ArcGIS 10.3是一个完整公布的ArcGIS平台,它包含新的产品(ArcGIS Pro),针对10.2版本号产品进行了功能增强和稳定性的改进. ArcGIS 10.3 for Server新特性 ...
- .NET Standard 2.0 特性介绍和使用指南
.NET Standard 2.0 发布日期:2017年8月14日 公告原文地址 前言 早上起来.NET社区沸腾了,期待已久的.NET Core 2.0终于发布!根据个人经验,微软的产品一般在2.0时 ...
- .Net大局观(2).NET Core 2.0 特性介绍和使用指南
.NET Core 2.0发布日期:2017年8月14日 前言 这一篇会比较长,系统地介绍了.NET Core 2.0及生态,现状及未来计划,可以作为一门技术的概述来读,也可以作为学习路径.提纲来用. ...
- .Net Core 2.0生态(4):Entity Framework Core 2.0 特性介绍和使用指南
前言 这是.Net Core 2.0生态生态介绍的最后一篇,EF一直是我喜欢的一个ORM框架,随着版本升级EF也发展到EF6.x,Entity Framework Core是一个支持跨平台的全新版本, ...
- .Net Core 2.0 生态(2).NET Core 2.0 特性介绍和使用指南
.NET Core 2.0发布日期:2017年8月14日 前言 这一篇会比较长,介绍了.NET Core 2.0新特性.工具支持及系统生态,现状及未来计划,可以作为一门技术的概述来读,也可以作为学习路 ...
随机推荐
- 【C# .Net GC】GC初始化设置 和GcSetting
相关的类 GcSetting 类 GCLargeObjectHeapCompactionMode 枚举 GCLargeObjectHeapCompactionMode 枚举 属性的值 GCSettin ...
- 用 UI 多线程处理 WPF 大量渲染的解决方案
众所周知, WPF 的 UI 渲染是单线程的,所以如果我们异步或者新建线程去进行数据处理的时候,处理完,想要更新 UI 的时候,需要调用一下 Dispatcher.Invoke,将处理完的数据推入到 ...
- 使用linux 的shell脚本进行sftp文件上传与下载
一.批量上传: #!/bin/bash #SFTP配置信息 #用户名 USER=root #密码 PASSWORD=5EYS40T04BMF #待上传文件根目录 SRCDIR=/u02/dab/sft ...
- 论文解读(GIN)《How Powerful are Graph Neural Networks》
Paper Information Title:<How Powerful are Graph Neural Networks?>Authors:Keyulu Xu, Weihua Hu, ...
- tomcat启动错误:Error running 'Tomcat 9.0.34': Address localhost:1099 is already in use
解决方法博客地址:https://blog.csdn.net/weixin_46697202/article/details/105782670
- js数组 把竖向数组排列为横向数组
项目中会遇到为了渲染方便要把后台给的竖向数组排列为横向数组 例:后台传回的数组为[2004, 2005, 2006, 2007, 2008] [46890000, 55900500, 33786400 ...
- hexo部署到github时,提示typeError [ERR_INVALID_ARG_TYPE] The “mode“ argument must be integer. Receive
hexo部署到github时,提示typeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Re ...
- 搞懂MySQL(各种)索引类型及其区别
索引的概念介绍: 1.聚集索引 聚集索引:指索引项的排序方式和表中数据记录排序方式一致的索引 也就是说聚集索引的顺序就是数据的物理存储顺序.它会根据聚集索引键的顺序来存储表中的数据,即对表的数据按索 ...
- 构造方法__construct()与析构方法__destruct() 构造方法:刚出生时婴儿的啼哭 析构方法:老人临终时的遗言
<?phpclass person{ var $name; var $sex; var $age;//构造方法 function __construct($name, $sex, $age) { ...
- larav jq ajax 登录
//自高自测登录8.10 Route::get('name/login','nameLoginController@login'); Route::post('/name/logins','nameL ...