I have an application that is written using C# on the top of Asp.Net MVC 5.
I have the following model
public class SomeViewModel
{
public IList<CheckBoxListItem> Days { get; set; }
......
}
public class CheckBoxListItem
{
public bool Checked { get; set; }
public string Value { get; set; }
public string Text { get; set; }
}
I want to be able to get the ModelMetadata for a single day aka CheckBoxListItem
in the Days
collection.
I tried the following to get the first day in the day's collection
// Attempt to get the ModelMetadata for the first item in the Days collection
ModelMetadata.FromStringExpression("Days[0]", html.ViewData);
// Attempt to get the ModelMetadata for the Checked property in the first item
ModelMetadata.FromStringExpression("Days[0].Checked", html.ViewData);
But the above does not return the ModelMetadata.
The following code returns the whole collection as expected.
ModelMetadata.FromStringExpression("Days", html.ViewData);
What is the correct expression to use to get the ModelMetadata for a single item in a collection?