私は、モデルクラスのいくつかのフィールドだけを表示し、オブジェクトの要約として使用するオブジェクトテンプレートを作成しています。私はSummary属性を作成し、その属性を持つ特定のフィールドにフラグを立てました。私は実際にプロパティがその属性を持っているかどうかを実際に判断する方法を見つけることができません。なぜなら、オブジェクトテンプレートには実際のプロパティがなくModelMetadataが代わりにあるからです。 プロパティにオブジェクトテンプレートの概要属性が含まれているかどうかを確認するにはどうすればよいですか?特定の属性を持つプロパティを表示するテンプレート?
public class Car
{
[Key]
public int CarKey { get; set;}
[Summary]
public string Color { get; set;}
public string EngineSize { get; set;}
[Summary]
public string Model { get; set;}
public int NumberOfDoors
}
これは私のオブジェクトのテンプレートです:
@if (Model == null) {
<text>@ViewData.ModelMetadata.NullDisplayText</text>
} else if (ViewData.TemplateInfo.TemplateDepth > 1) {
<text>@ViewData.ModelMetadata.SimpleDisplayText</text>
} else {
<table cellpadding="0" cellspacing="0" border="0">
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm))) {
if(prop./******************** what goes here ************************/
if (prop.HideSurroundingHtml) {
<text>@Html.Display(prop.PropertyName)</text>
} else {
<tr>
<td>
<div class="display-label" style="text-align: right;">
@prop.GetDisplayName()
</div>
</td>
<td>
<div class="display-field">
@Html.Display(prop.PropertyName)
</div>
</td>
</tr>
}
}
</table>
}
ありがとう、属性は私のものですので、これは問題ではありません。私はMVCを愛する! AutoMapperと組み合わせて、私がASP.NETに望んだことは、かなり長い間のようでした。 – AaronLS