Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could create a custom collection type and name the editor to match that.</p> <p>Assuming you created custom collection called <code>Tags</code> you could change your model to:</p> <pre><code>class MyModel { Tags Tags { get; protected set;} } </code></pre> <p>Then you would name your editor and display templates <code>Tags.ascx</code>.</p> <p>Which would make your view code work like you wanted:</p> <pre><code>&lt;%= Html.EditorFor(t =&gt; t.Tags) %&gt; </code></pre> <p>For the custom collection you basically just create a wrapper around an implementation of a generic collection and expose it's methods and properties:</p> <pre><code>public class Tags : IList&lt;Tag&gt; { //Use a private List&lt;Tag&gt; to do all the //heavy lifting. private List&lt;Tag&gt; _tags; public Tags() { _tags = new List&lt;Tag&gt;(); } public Tags(IEnumerable&lt;Tag&gt; tags) { _tags = new List&lt;Tag&gt;(tags); } #region Implementation of IEnumerable public IEnumerator&lt;Tag&gt; GetEnumerator() { return _tags.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return _tags.GetEnumerator(); } #endregion #region Implementation of ICollection&lt;Tag&gt; public void Add(Tag tag) { _tags.Add(tag); } public void Clear() { _tags.Clear(); } public bool Contains(Tag tag) { return _tags.Contains(tag); } public void CopyTo(Tag[] array, int arrayIndex) { _tags.CopyTo(array, arrayIndex); } public bool Remove(Tag tag) { return _tags.Remove(tag); } public int Count { get { return _tags.Count; } } public bool IsReadOnly { get { return false; } } #endregion #region Implementation of IList&lt;Tag&gt; public int IndexOf(Tag tag) { return _tags.IndexOf(tag); } public void Insert(int index, Tag tag) { _tags.Insert(index, tag); } public void RemoveAt(int index) { _tags.RemoveAt(index); } public Tag this[int index] { get { return _tags[index]; } set { _tags[index] = value; } } #endregion } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload