I added a field to a view model for a Document that should allow the user to associate it with a Tenant. It works fine if the user does assign a tenant, but if they select the null option from the dropdown, then the validation tells me that "The ItemID field is required.", where ItemID is a field on TenantViewModel.
It occurs to me that perhaps I'm using editor templates wrong - I'm trying to select from a list of tenants, not edit a tenant. If that's wrong, let me know, and maybe suggest a better way to get the dropdown.
namespace TenantPortal.Models
{
public class DocumentViewModel
{
...
[UIHint("SelectTenant")]
public TenantViewModel Tenant { get; set; }
}
public class TenantViewModel
{
private Tenant _ten = null;
public int ItemID { get; set; }
public string Display_Name { get; set; }
public string Legal_Name { get; set; }
...
}
}
Editor Template: SelectTenant.cshtml
@using CMS.DocumentEngine.Types.Tenantportal
@using TenantPortal.Models
@model TenantViewModel
@{
Layout = null;
var opts = new SelectList(TenantProvider.GetTenants(), "ItemID", "Display_Name");
}
@Html.DropDownListFor(model => model.ItemID, opts, "(none)")