设置默认输入值Datetime.Now创建视图MVC ASP.NET Core 2吗? [英] Set default input value Datetime.Now on create view MVC ASP.NET Core 2?

查看:48
本文介绍了设置默认输入值Datetime.Now创建视图MVC ASP.NET Core 2吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置输入OpenDate的默认值为服务器的日期和时间.

How can I set default value of input OpenDate is date and time of server.

<div class="form-group">
   <label asp-for="OpenDate" class="control-label">Ngày đăng ký</label>
   <input asp-for="OpenDate" class="form-control" />
   <span asp-validation-for="OpenDate" class="text-danger"></span>
</div>

推荐答案

在您的模型中:
[BindNever]
public System.DateTime OpenDate {get;放;}

在您的控制器中(您要在其中发布表单的地方)
yourModel.OpenDate = DateTime.Now;

In your Controller (where you are posting the form)
yourModel.OpenDate = DateTime.Now;

在您的视图中:
您可以排除已发布的代码,因为不需要它.

In your View:
You can exclude the code that you have posted, because it will not be needed.

注意:我使用了"BindNever",因为您可以从模型绑定中排除此属性.这是系统将为您获取的数据.

Note: I used "BindNever" because you can exclude this property from the model binding. It is a data that the system will get for you.

这篇关于设置默认输入值Datetime.Now创建视图MVC ASP.NET Core 2吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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