且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将一天添加到模型数据中

更新时间:2023-12-01 20:40:22

您也可以使用DateTime.AddDays()方法将NextDay作为DateTime传递给Model. 此方法返回一个新的DateTime,该DateTime将指定的天数添加到该实例的值中.

You can pass the NextDay as a DateTime in the Model as well using DateTime.AddDays() method. This method returns a new DateTime that adds the specified number of days to the value of this instance.

model.NextDay = startDate.AddDays(1);

然后在DisplayNameFor中使用该属性:

<a href="@Html.DisplayNameFor(model => model.NextDay)">Next Day</a>

MSDN

此方法不会更改此DateTime的值.而是返回一个新的DateTime,其值是此操作的结果.

This method does not change the value of this DateTime. Instead, it returns a new DateTime whose value is the result of this operation.