This seems like a really basic scenario, but I think it doesn't have a happy ending.
I have a simple project class:
public class Project
{
[Required(ErrorMessage = "Project title is required")]
[DisplayName("Project Title")]
public string Title { get; set; }
[DisplayName("Related Categories")]
public Category Categories { get; set; }
}
I want to ensure at least one related Category is selected. How can I validate this in the view, using Html.EnableClientValidation(), and decorators in the model? If this isn't possible, what is the fallback?
Equally frustrating, and probably an hindrance to validation is that I can't do...
<%= Html.ListBoxFor(m => m.Project.Categories,
new SelectList(Model.Categories, "Id", "Name"))%>
...because this will attempt to associate the Project.Categories form value (a string array) to what should be a Category type, but won't be able to (I get an error "The parameter conversion from type 'System.String' to type failed because no type converter can convert between these types"). Therefore, I have to change the form name to something like m.Categories, thus disassociating from the Product class, and therefore any validation logic I would like to decorate it with.
Wow, to me this is crazy. We can't validate a simple multiselect list, using MVC2 decorators?