将一天添加到模型数据中 [英] Add one day to a model's data

查看:75
本文介绍了将一天添加到模型数据中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Razor的新手,我想知道如何为模型的日期对象添加一天.我需要放置一个第二天"链接

I am new to Razor and I want to know how to add one day to model's date object. I need to put a "next day" link

这是查看代码

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

推荐答案

您也可以使用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.

这篇关于将一天添加到模型数据中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆