I am trying to create DisplayTemplates -> Object.cshtml template and from it pickup property templates for specified fields. I will provide example to show the problem.
The view model
public class UserViewModel
{
public string FullName { get; set; }
public string Email { get; set; }
[DataType(DataType.Date)]
public string DateStamp { get; set; }
}
I want to display this model in View.cshtml like this
@model CAWP.Models.UserViewModel
<fieldset>
<legend>User Information </legend>
@Html.DisplayForModel(Model)
</fieldset>
My ASP.NET MVC DisplayTemplates folder has two files Object.cshtml and Date.cshtml.
The Object.cshtml looks like
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(p => p.ShowForDisplay))
{
<div class="display-label">@prop.DisplayName</div>
<div class="display-field">@Html.Display(prop.PropertyName)</div>
}
The Date.cshtml is created special for UserViewModel.DateStamp property
<time datetime="@ViewData.TemplateInfo.FormattedModelValue" data-date-format="date"></time>
So the problem is that @Html.Display(prop.PropertyName) in Object.cshtml never put UserViewModel.DateStamp into Date.cshtml template. Any ideas why it is not working?
Actually the problem was
should be
I have no idea how these two are differt.