|
这个问题需要新版本解决。下个版本我们会支持RenderFieldFor和RenderCheckFieldFor,配合EF使用会比较方便。
老版本这样的代码:
- @{
- ViewBag.Title = "Grid/Grid";
- var F = Html.F();
- }
- @section body {
- @(F.Grid()
- .EnableCollapse(true)
- .Width(850)
- .Title("表格")
- .ShowHeader(true)
- .ShowBorder(true)
- .ID("Grid1")
- .DataIDField("Id")
- .DataTextField("Name")
- .Columns(
- F.RowNumberField(),
- F.RenderField()
- .HeaderText("姓名")
- .DataField("Name")
- .Width(100),
- F.RenderField()
- .HeaderText("性别")
- .DataField("Gender")
- .FieldType(FieldType.Int)
- .RendererFunction("renderGender")
- .Width(80),
- F.RenderField()
- .HeaderText("入学年份")
- .DataField("EntranceYear")
- .FieldType(FieldType.Int)
- .Width(100),
- F.RenderCheckField()
- .HeaderText("是否在校")
- .DataField("AtSchool")
- .RenderAsStaticField(true)
- .Width(100),
- F.RenderField()
- .HeaderText("所学专业")
- .DataField("Major")
- .RendererFunction("renderMajor")
- .ExpandUnusedSpace(true),
- F.RenderField()
- .HeaderText("分组")
- .DataField("Group")
- .RendererFunction("renderGroup")
- .Width(80),
- F.RenderField()
- .HeaderText("注册日期")
- .DataField("LogTime")
- .FieldType(FieldType.Date)
- .Renderer(Renderer.Date)
- .RendererArgument("yyyy-MM-dd")
- .Width(100)
- )
- .DataSource(DataSourceUtil.GetDataTable())
- )
- }
复制代码
新版本可以简化为:
- @{
- ViewBag.Title = "DataModel/Grid";
- var F = Html.F();
- }
- @model List<FineUIMvc.Examples.Areas.DataModel.Models.Student>
- @section body {
- @(F.Grid()
- .EnableCollapse(true)
- .Width(850)
- .Title("表格")
- .ShowHeader(true)
- .ShowBorder(true)
- .ID("Grid1")
- .DataIDField("Id")
- .DataTextField("Name")
- .Columns(
- F.RowNumberField(),
- F.RenderFieldFor(m => m.Name),
- F.RenderFieldFor(m => m.Gender)
- .RendererFunction("renderGender")
- .Width(80),
- F.RenderFieldFor(m => m.EntranceYear),
- F.RenderCheckFieldFor(m => m.AtSchool)
- .RenderAsStaticField(true),
- F.RenderFieldFor(m => m.Major)
- .RendererFunction("renderMajor")
- .ExpandUnusedSpace(true),
- F.RenderFieldFor(m => m.Group)
- .RendererFunction("renderGroup")
- .Width(80),
- F.RenderFieldFor(m => m.EntranceDate)
- )
- .DataSource(Model)
- )
- }
复制代码
当然,这种方式就不支持DataTable了,而需要定义实体类(配合EntityFramework会比较爽):
- public class Student
- {
- [Key]
- public int Id { get; set; }
- [Required]
- [Display(Name = "姓名")]
- [StringLength(20)]
- public string Name { get; set; }
- [Required]
- [Display(Name = "性别")]
- public int Gender { get; set; }
- [Required]
- [Display(Name = "入学年份")]
- public int EntranceYear { get; set; }
- [Required]
- [Display(Name = "是否在校")]
- public bool AtSchool { get; set; }
- [Required]
- [Display(Name = "所学专业")]
- [StringLength(200)]
- public string Major { get; set; }
- [Required]
- [Display(Name = "分组")]
- public int Group { get; set; }
- [Display(Name = "注册日期")]
- [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
- public DateTime? EntranceDate { get; set; }
- }
复制代码
|
|