BootstrapBlazor - EditorForm 表單組件(一)


原文鏈接:https://www.cnblogs.com/ysmc/p/16053652.html

官網例子鏈接:https://www.blazor.zone/editorforms

通過綁定數據模型自動呈現編輯表單

EditorForm 組件是一個非常實用的組件,當進行數據編輯時,僅需要將 Model 屬性賦值即可。

  • 綁定模型默認自動生成全部屬性,可以通過設置 AutoGenerateAllItem 更改為不自動生成
  • 如不需要編輯列,設置 Editable 即可,默認值為 true 生成編輯組件
  • 復雜編輯列,設置 EditTemplate 模板,進行自定義組件進行編輯
  • 表單內按鈕可以設置多個,設置 Buttons 模板即可
<EditorForm Model="@Model">
   <FieldItems>
      <EditorItem @bind-Field="@context.Education" Editable="false" />
         <EditorItem @bind-Field="@context.Complete" Editable="false" />
         <EditorItem @bind-Field="@context.Hobby" Items="@Hobbys" />
      </FieldItems>
      <Buttons>
         <Button Icon="fa fa-save" Text="提交" />
      </Buttons>
</EditorForm>

Attributes 屬性

參數
說明
類型
可選值
默認值
Model
當前綁定數據模型
TModel
FieldItems
綁定列模板
RenderFragment<TModel>
Buttons
按鈕模板
RenderFragment
IsDisplay
是否顯示為 Display 組件
bool
true/false
false
ShowLabel
是否顯示 Label
bool
true/false
true
ShowLabelTooltip
鼠標懸停標簽時顯示完整信息
bool?
true/false/null
null
AutoGenerateAllItem
是否生成所有屬性
bool
true/false
true
ItemsPerRow
每行顯示組件數量
int?
RowType
設置組件布局方式
RowType
Row|Inline
Row
LabelAlign
Inline 布局模式下標簽對齊方式
Alignment
None|Left|Center|Right
None

 AttrAttributeTitle

參數
說明
類型
可選值
默認值
Field
當前綁定數據值
TValue
FieldType
綁定列數據類型
Type
Editable
是否允許編輯
bool
true/false
true
Readonly
是否只讀
bool
true/false
false
Text
編輯列前置標簽名
string
EditTemplate
列編輯模板
RenderFragment<object>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM