標準DisplayFormat
属性では、これを許可していません。
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class LocalizedDisplayFormatAttribute : Attribute, IMetadataAware
{
public string DataFormatStringResourceName { get; set; }
public bool ApplyFormatInEditMode { get; set; }
public void OnMetadataCreated(ModelMetadata metadata)
{
if (!string.IsNullOrEmpty(DataFormatStringResourceName))
{
if (ApplyFormatInEditMode)
{
metadata.EditFormatString = MyMessages.ResourceManager.GetString(DataFormatStringResourceName);
}
metadata.DisplayFormatString = MyMessages.ResourceManager.GetString(DataFormatStringResourceName);
}
}
}
、その後:
public class MyViewModel
{
[LocalizedDisplayFormat(DataFormatStringResourceName = "DobFormat", ApplyFormatInEditMode = true)]
public DateTime Dob { get; set; }
}
とMyResources.resx
の内側にあなたがDobFormat
文字列値可能性があり:{0:dd-MM-yyyy}
をあなたはこの機能を実現するためにカスタム属性を書くことができます。
私はこれを自分で行う必要があると考えました。ありがとう –
'MyMessages'は' MyResources'権利ですか?それが型として渡されたならば完璧だったでしょう – CME64