2011-11-02 39 views
0

我一直在阅读各种关于如何处理复杂类型的博客文章,其中包括大多数人似乎都链接的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

解决。

在EditorTemplates文件夹中创建模板Tags.vbhtml并应用于PostTag。该模板具有显示在视图中的文本框。