我在日期字段中只有一个小测验编辑“年”部分。 我尝试过一种带有格式属性的天真方法:
Partial Public Class Book
Public Property BookID As Integer
Public Property Title As String
Public Property Author As String
<DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0:yyyy}")>
Public Property Year As Nullable(Of Date)
Public Property CategoryID As Integer
Public Property Image As Byte()
Public Overridable Property Category As Category
End Class
我的观点是
<div class="editor-field">
<%: Html.EditorFor(Function(model) model.Year)%>
<%: Html.ValidationMessageFor(Function(model) model.Year)%>
</div>
但它不起作用。当我在输入字段中写“2014”并按“提交”验证检查器告诉我“2014”不是有效日期。 那么我该如何解决这个问题?