我真的搜索过并且没有找到答案。鉴于一篇文章可以有多个标签,我想将标签显示为逗号分隔值,以便在编辑文章时在textarea中看起来像Egypt, Sinai, Muslim Brotherhood
。我将发布所需的任何代码,如果这将有助于答案。
我的模特是:
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
我正在使用现有的数据库和数据,模型是从Code First From Database生成的。
我意识到我需要一个EditorTemplate,但除此之外,我不知道该怎么做。如何将多个值绑定到单个textarea?
显示我在说什么的图片:
答案 0 :(得分:1)
解决:
把它扔进编辑器模板:
@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