使用 EditorForModel() 时如何获取要呈现的时间戳属性?
我有以下用 System.ComponentModel.DataAnnotations 装饰的域实体:
[HiddenInput(DisplayValue=false)]
public int Id { get; set; }
[Required]
[Display(Name="Last Name")]
public string LastName { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Timestamp]
[HiddenInput(DisplayValue=true)]
[ScaffoldColumn(true)]
public byte[] Version { get; set; }
当我使用 @Html.EditorForModel()
在视图中渲染模型时,不会为版本属性渲染任何内容。有什么可以强制 EditorForModel()
方法渲染 byte[]
吗?
PS:使用 @Html.EditorFor(x => x.Version)
效果很好。
I have the following domain entity decorated with System.ComponentModel.DataAnnotations:
[HiddenInput(DisplayValue=false)]
public int Id { get; set; }
[Required]
[Display(Name="Last Name")]
public string LastName { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Timestamp]
[HiddenInput(DisplayValue=true)]
[ScaffoldColumn(true)]
public byte[] Version { get; set; }
When I render my model in the view using @Html.EditorForModel()
nothing is rendered for the version property. Is there anything that can force EditorForModel()
method to render the byte[]
?
PS: Using @Html.EditorFor(x => x.Version)
works just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以创建一个名为 Version 的 EditorTemplate 并按照您认为合适的方式设计输出。向版本添加 UIHint 属性以便使用它。
You could also create an EditorTemplate named Version and design the output how you see fit. add a UIHint attribute to version in order to use it.
byte[]
被EditorForModel
方法视为复杂类型,目前无法显示这些类型。您可以尝试向模型添加另一个属性(例如,输入为string
),该属性将从您的Version
属性中读取和写入。A
byte[]
is considered to be a complex type by theEditorForModel
method and there currently is no way for those to be displayed. You could try adding another property to your model (typed asstring
for example) that would read from and write to yourVersion
property.最好编写自己的模板(Object.ascx)。
复制标准 MVC Object.ascx 模板并将 ShouldShow Method 更改为:
Better write your own template (Object.ascx).
Copy the standard MVC Object.ascx template and change the ShouldShow Method to: