简体   繁体   English

呈现复杂类型的文本框?

[英]Rendering a textbox for a complex type?

I have been reading the various blog posts on how to deal with a Complex Type in EF including the brad wilson post which most everyone seems to link. 我一直在阅读有关如何处理EF中的复杂类型的各种博客文章,包括大多数人似乎都链接的brad wilson文章。 owever i dont really get it. 但是,我真的不明白。 I am using EF code first development, MVC and VB. 我正在使用EF代码优先开发,MVC和VB。 From what i have read so far to render a editor field for a complex types requires a custom object, right? 到目前为止,从我所读到的内容来看,为复杂类型呈现编辑器字段需要一个自定义对象,对吗? However i dont really understand what code i need to put into the custom template. 但是我真的不明白我需要在自定义模板中放入什么代码。 Can someone break it down for me as to what code needs to go into custom templete so i can render a textbox for the PostTags icollection? 有人可以帮我分解一下进入定制模板的代码,以便为PostTags icollection渲染文本框吗?

My classes: 我的课程:

 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    

Solved. 解决了。

Created the template Tags.vbhtml in the EditorTemplates folder and applied to PostTags. 在EditorTemplates文件夹中创建了模板Tags.vbhtml并将其应用于PostTags。 the template has the textbox which is shown in the view. 模板具有在视图中显示的文本框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM