I created a business object (plain old class with properties, nothing fancy), that has an empty constructor, and I am using it as a strong type in my View for /Member/Create (see code).
This all works fine, I get the object "post back" from the Create View - and my method memberToCreate.Save() actually writes what it is supposed to, to the database.
But after that is done, the create view is displayed again, and the fields that are guid- and datetime-types raise a validation error ("A value is required") - unless they are readonly properties.
I don't want to set the properties to read only, since they are needed as writeable from other places.
How do I get around this? Can I "tag" a property as required/not required?
'
' GET: /Member/Create
Function Create() As ActionResult
Return View()
End Function
'
' POST: /Member/Create
<AcceptVerbs(HttpVerbs.Post)> _
Function Create(<Bind(Exclude:="MemberId")> ByVal memberToCreate As Biz.Member) As ActionResult
memberToCreate.Save()
Return View()
End Function
This get me the validation error:
Public Property DateOfBirth() As Date
Get
Return _DateOfBirth
End Get
Set(ByVal value As Date)
_DateOfBirth = value
End Set
End Property
This does not...
Public Readonly Property DateOfBirth() As Date
Get
Return _DateOfBirth
End Get
End Property