Format date within View in ASP.NET Core MVC

前端 未结 9 2167
借酒劲吻你
借酒劲吻你 2020-12-30 09:51

I have problem in regarding with converting the datetime to date using a model.

Model from Class Library

public partial class LoanCo         


        
9条回答
  •  孤独总比滥情好
    2020-12-30 10:29

    For those who get here wanting to change date format of a model in the view regardless of Model class (Its what I expected to be answering). This works in both Razorpages and MVC.

    Just add .ToString("dd/MM/YYYY") to the property you're displaying.

    e.g.

    @Model.DateOfBirth.ToString("")
    

    This is great if you only want to show part of a date say month and year, but elsewhere you need to show the day and the time.

提交回复
热议问题