C#/ASP.net

[.net MVC Core] Model의 Data의 DisplayFormat 바꾸기 (날짜, 통화)

saltdoll 2017. 4. 26. 07:25
반응형

MVC에 Model에서 데이터어노테이션을 통해서, 모델의 표시를 바꿔보도록 합니다.

 

 

public class CostChart
{
    public string itemType { get; set; }
    [DataType(DataType.Currency)]
    public float? Cost{ get; set; }

}

Alternatively, you could use?DataFormatString?like this:

[DisplayFormat(DataFormatString = "{0:C0}")]`
public float? Cost{ get; set; }

But I prefer to set the display format with?EditorFor. Here's a great tutorial on Extending Editor Templates for ASP.NET MVCtutorial.

That way, you write the display logic of your currencies in just ONE place, and you don't need to add that extract annotation every single time you want to display a currency amount.

출처: http://stackoverflow.com/questions/29975128/asp-net-mvc-data-annotation-for-currency-format

참고: https://www.simple-talk.com/dotnet/asp.net/extending-editor-templates-for-asp.net-mvc/

 

 

 

 

반응형