在文本区域中显示来自数据库的逗号分隔值?
Showing Comma separated values from database in a textarea?
我真的找了找了也没有找到答案。鉴于一篇文章可以有多个标签,我想将标签显示为逗号分隔值,以便在编辑文章时它看起来像 Egypt, Sinai, Muslim Brotherhood
在文本区域中。如果对答案有帮助,我将 post 提供所需的任何代码。
我的模型是:
Partial Public Class be_Posts
<Key>
Public Property PostRowID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(255)>
Public Property Title As String
Public Property Description As String
<AllowHtml> Public Property PostContent As String
Public Property DateCreated As Date?
Public Property DateModified As Date?
<StringLength(50)>
Public Property Author As String
Public Property IsPublished As Boolean?
Public Property IsCommentEnabled As Boolean?
Public Property Raters As Integer?
Public Property Rating As Single?
<StringLength(255)>
Public Property Slug As String
Public Property IsDeleted As Boolean
Public Overridable Property be_PostTag As ICollection(Of be_PostTag)
Public Overridable Property be_Categories As ICollection(Of be_Categories)
End Class
和 be_PostTag 模型
Partial Public Class be_PostTag
<Key>
Public Property PostTagID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(50)>
Public Property Tag As String
Public Property be_Posts As ICollection(Of be_Posts)
End Class
我正在使用现有的数据库和数据,模型是从数据库中的代码优先生成的。
我意识到我需要一个 EditorTemplate 但除此之外我不知道该做什么。我如何将多个值绑定到单个文本区域?
一张图片来说明我在说什么:
已解决:
将其放入编辑器模板中:
@modeltype IEnumerable(Of BetterBlog.Core.Entities.be_PostTag)
@code
Dim sb As New StringBuilder
For Each x In Model
Dim tags = x.Tag & IIf(x.Equals(Model.Last), "", ", ")
sb.Append(tags)
Next
@Html.TextArea("PostTags", sb.ToString, 10, 50, nothing)
End Code
我真的找了找了也没有找到答案。鉴于一篇文章可以有多个标签,我想将标签显示为逗号分隔值,以便在编辑文章时它看起来像 Egypt, Sinai, Muslim Brotherhood
在文本区域中。如果对答案有帮助,我将 post 提供所需的任何代码。
我的模型是:
Partial Public Class be_Posts
<Key>
Public Property PostRowID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(255)>
Public Property Title As String
Public Property Description As String
<AllowHtml> Public Property PostContent As String
Public Property DateCreated As Date?
Public Property DateModified As Date?
<StringLength(50)>
Public Property Author As String
Public Property IsPublished As Boolean?
Public Property IsCommentEnabled As Boolean?
Public Property Raters As Integer?
Public Property Rating As Single?
<StringLength(255)>
Public Property Slug As String
Public Property IsDeleted As Boolean
Public Overridable Property be_PostTag As ICollection(Of be_PostTag)
Public Overridable Property be_Categories As ICollection(Of be_Categories)
End Class
和 be_PostTag 模型
Partial Public Class be_PostTag
<Key>
Public Property PostTagID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(50)>
Public Property Tag As String
Public Property be_Posts As ICollection(Of be_Posts)
End Class
我正在使用现有的数据库和数据,模型是从数据库中的代码优先生成的。
我意识到我需要一个 EditorTemplate 但除此之外我不知道该做什么。我如何将多个值绑定到单个文本区域?
一张图片来说明我在说什么:
已解决:
将其放入编辑器模板中:
@modeltype IEnumerable(Of BetterBlog.Core.Entities.be_PostTag)
@code
Dim sb As New StringBuilder
For Each x In Model
Dim tags = x.Tag & IIf(x.Equals(Model.Last), "", ", ")
sb.Append(tags)
Next
@Html.TextArea("PostTags", sb.ToString, 10, 50, nothing)
End Code