首页 > 解决方案 > Visual Studio 2017 Movierental 日期设置

问题描述

我有一个电影租赁应用程序,它基于就像在电影院订票但它需要特定的场景

“示例毒液:让大屠杀于 2021 年 6 月 25 日发布”

我的目标是让它无法“在电影上映日期之前预订票”

这是我的代码。

<div class="form-group">
            @Html.LabelFor(model => model.Schedule, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <input type="date" name="Schedule" required />
            </div>
        </div>

标签: phphtmlsqlasp.net-mvc

解决方案


In POST Action, you can compare the date.

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(MyModel My)
{
    if (ModelState.IsValid)
    {
        if (My.Schedule > DateTime.Today)
        {
            ModelState.AddModelError(string.Empty, "Movie has not released yet.");
            return View();
        }
        //Otherwise do further process here
    }
    return View();
}

推荐阅读