I'm fairly new to MVC so please bear this in mind
I have created a viewmodel vmRecurringPack which contains another model Entity amongst other fields in its properties. In the view that I am passing vmRecurringPack, I am only using some of the Entity properties for display purposes (The remaining fields are not required for my view)
My issue arises in that when I POST my view back, the remaining fields of course haven't been bound to the view, and have lost their value. This part is fine in my case, however ModelState.IsValid no longer works because some of those fields are required.
How can I work around this without removing ModelState.IsValid?
(VB.net answers preferable, C# welcome)
EDIT: I have considered a restructure of my viewmodel, which would work, however I'm curious as to what other solutions exist
EDIT: As requested, code. Although I don't see how its required for this particular question... In relation to my question, I want to display the fields for vmRecurringPack.Entity.Code and vmRecurringPack.Entity.Name but in my form POST the ModelState.IsValid returns false because of the fields marked required in Entity coming through as nothing
vmRecurringPack
Namespace ViewModels
Public Class vmRecurringPack
Property Entity As Entity
Property Name As String
Property Description As String
Property Status As String
End Class
End Namespace
Entity
Namespace Models
Public Class Entity
Public Property Id As Integer
<Required>
Public Property Name As String
<Required>
<StringLength(5)>
Public Property Code As String
<Required>
<StringLength(7)>
Public Property Abbrv As String
Public Property Status As Boolean
<DataType(DataType.EmailAddress)>
Public Property Email As String
Public Overridable Property EntityType As EntityType
Public Overridable Property ReportLists As ICollection(Of ReportList) = New HashSet(Of ReportList)
Public Overridable Property Packages As ICollection(Of Packages) = New HashSet(Of Packages)
End Class
End Namespace