Description of the problem
My problem is similar to this question , but instead of applying annotations to the property name through reflection (processed by ModelMetadata.DisplayName) I apply them to the value (not processed by ModelMetadata).
Detailed description
In the context of an ASP.NET MVC program.
Suppose I have a Model class
public class Model
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string NickName { get; set; }
public string Address { get; set; }
public int Phone { get; set; }
[Display(Name = "Start Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime StartDate { get; set }
[Display(Name = "End Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime EndDate { get; set }
}
Then suppose that this Model is used in at least 5 different representations, where the value of each property should be fully displayed. (Sometimes for each instance, sometimes for several, sometimes for one).
I can manually list each access to the properties inside it.
<td>@Html.DisplayFor(item.<Property>)</td>
for each species.
, Model , (, , ). .
PropertyInfo ,
<td>@property.GetValue(item)</td>
DisplayFor(x) , x=>property.GetValue(item), , , DateTime
01/01/1990
01-Jan-90 12:00:00 AM
, , , .
( ) :
- [Failed] ,
@property.GetValue(item)
[] - [Failed] DisplayFor MethodInfo, Access Accessor
DisplayFor(x => property.GetGetMethod()), .Invoke x.
[/Edit] - , ,
- , , ,
- DisplayFor " " DisplayFor,
- Model (SortedList?) "Prop", "Prop" - , Name Value.
@Html.DisplayFor(m=>property.GetValue(item)
@Html.DisplayFor(m=>item.Properties[i].Value)
, "" ( [ "" ]) (.Value), .
[]
Utility, DisplayFormatAttribute PropertyInfo DisplayFormatString, "{0}", . ViewModel.
, , " ", .
[/Edit]
, ...
, , ? ?
, , , , , ?