The following is a view models in ASP.NET MVC:
public class Email
{
public string Selected { get; set; }
public string Name { get; set; }
}
public class User
{
public string UserName { get; set; }
public IList<Email> Emails { get; set; }
}
It is passed into the view and looks like this while defining the knockout view model:
var viewModel = {
UserName: ko.observable("@Model.UserName"),
Emails: ko.observableArray(@Html.Json(@Model.Emails) || []),
// many other things
}
I want to make sure that Email.Selected
is required
. How to do it having the list, rather than single objects. I know it must be the easiest question, but I couldn't find anything on the topic.
I use knockout validation on the client, since Fluent and data annotation aren't working with knockout unfortunately.