I'm trying to make an EditorFor and Editor Template for a custom class that maps to a drop down UI element. The idea is to select n-number of items from the collection and then process those selections on a form post.
The problem I'm having is that even though the ViewModel property for my collection isn't null, fyi I'm passing a viewmodel as the parameter in the controller method, it is always empty.
This is leading me to believe that I'm missing a mapping step somewhere or improperly creating the input/html.
The input element that has the values of the selected items contains a list of MyCollectionItem Id's. I was expecting to see at least a list of those id's (other values would obviously not be included, so I was thinking they'd just be null or default values) but instead I get an empty collection.
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace MyApp
{
public class MyCollection : Collection<MyCollectionItem>
{
public MyCollection (IList<MyCollectionItem> list) : base(list) { }
public MyCollection () { }
}
public class MyCollectionItem
{
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime CreatedDate { get; set; }
}
}
In the editor template:
@model MyApp.MyCollection
<div class="ui sub header">Selection:</div>
<div class="ui fluid multiple search selection dropdown">
<input name="MyCollection" id="MyCollection" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Please Make a Selection</div>
<div class="menu">
@foreach (var item in Model)
{
<div class="item" data-value="@item.Id">@item.Name</div>
}
</div>
</div>
I would appreciate if someone could point out where I'm making my main mistakes, and how to more properly generate the template or map form data to be passed into the controller.