我一直在阅读有关如何处理EF中的复杂类型的各种博客文章,包括大多数人似乎都链接的brad wilson帖子。不管我真的没有。我正在使用EF代码首先开发,MVC和VB。从我到目前为止所读到的为复杂类型呈现编辑器字段需要一个自定义对象,对吗?但是我真的不明白我需要在自定义模板中添加什么代码。有人可以为我分解为什么代码需要进入自定义模板,以便我可以为PostTags icollection渲染文本框?
我的课程:
Public Class Post
Inherits EntityBase
<Key()> Property PostId As Integer
<DisplayName("Title")> <Required()> Property PostTitle As String
<UIHint("MultilineText")> <DisplayName("Text")> Property PostText As String
ReadOnly Property PostExcerpt As String
Get
If PostText.Length > 100 Then
Return Helpers.TruncateHelper.TruncateAtWord(PostText, 250)
Else : Return PostText
End If
End Get
End Property
<ScaffoldColumn(False)> Property PostDateCreated As DateTime
<ScaffoldColumn(False)> Property PostDateModified As DateTime?
<ScaffoldColumn(False)> Property PostDatePublished As DateTime?
<DisplayName("Publish?")> Property PostIsPublished As Boolean
<DisplayName("Allow Comments?")> Property CommentsAllowed As Boolean
<ScaffoldColumn(False)> Property CategoryId As Integer?
<UIHint("Text")> <DisplayName("Category")> <Required()> Property PostCategory As String
Property Comments As IList(Of Comment)
'Post has collection of Tags
<DisplayName("Tags (comma separated)")> Overridable Property PostTags As ICollection(Of Tag)
End Class
Public Class Tag
Dim _rdsqlconn As RDSQLConn
<Key()> Property TagId As Int32
Property PostId As Int32
Property TagWord As String
'Overridable property to access Post
Overridable Property Post As Post
End Class
答案 0 :(得分:0)
解决。
在EditorTemplates文件夹中创建模板Tags.vbhtml并应用于PostTags。模板具有视图中显示的文本框。