c# - 如何比较 razor mvc 中的两个日期?
问题描述
给定以下代码:
我的剃刀代码是这个:
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table cellpadding="0" cellspacing="0">
<tr>
<td>Date: </td>
<td>
<div class="form-group input-group-sm">
@Html.LabelFor(model => model.StartDate)
@Html.TextBoxFor(model => model.StartDate, new { @class = "form-control datepicker", placeholder = "Enter Drop-off date here..." })
@Html.ValidationMessageFor(model => model.StartDate)
</div>
</td>
</tr>
<tr>
<td>end date: </td>
<td>
<div class="form-group input-group-sm">
@Html.LabelFor(model => model.EndDate)
@Html.TextBoxFor(model => model.EndDate, new { @class = "form-control datepicker", placeholder = "Enter Drop-off date here..." })
@Html.ValidationMessageFor(model => model.EndDate)
</div>
</td>
</tr>
</table>
}
我的模型是这个:
public class MyModel
{
[Display(Name = "From")]
[Required]
public DateTime StartDate { get; set; }
[Display(Name = "To")]
[Required]
public DateTime EndDate { get; set; }
}
你能给我一个方法来检查 StartDate 是否低于 EndDate 吗?谢谢
解决方案
使用这个我希望有用:
@if (Model.StartDate < Model.EndDate )
{
//Do something
}
推荐阅读
- c# - 如何在 C# Winform 应用程序中的表单之间传递裁剪的图片?
- python - 无法从 MainFrame(ttk.Frame) 类中关闭 tkinter 应用程序:
- java - Android 应用程序在从蓝牙 GPS 设备获取数据时速度变慢
- flutter - 如何通过智能手机热点运行颤振项目
- java - WebGPU JsInterop 包装器
- bash - bash 重定向到文件添加了意外的 0A 字节
- python - Python在类中设置变量类型
- web-scraping - 使用scrapy从多个页面收集一项的信息(并将其输出为嵌套字典)
- c# - 从 Guid C# 生成比特币公钥/私钥
- sql-server - 如何删除 DEFAULT 约束?