在ASP.NET中,可以使用文本框的TextMode
属性来指定日期时间的输入模式。要使用DateTimeLocal
格式,可以将TextMode
属性设置为DateTimeLocal
。
在ASP.NET Web Forms中,可以通过以下方式实现:
在ASP.NET MVC中,可以通过以下方式实现:
@Html.TextBoxFor(model => model.DateTimeProperty, new { type = "datetime-local" })
注意,DateTimeLocal
格式的支持取决于客户端浏览器的支持情况。不同的浏览器可能会在日期时间输入方面存在差异。
在服务器端,可以通过以下方式访问文本框的值:
在Web Forms中:
protected void btnSubmit_Click(object sender, EventArgs e)
{
DateTime selectedDateTime = DateTime.Parse(txtDateTime.Text);
// 处理选定的日期时间
}
在MVC中,可以在Controller的Action方法中使用ViewModel来接收值:
[HttpPost]
public ActionResult Submit(DateTime dateTimeProperty)
{
// 处理选定的日期时间
return View();
}
以上代码示例展示了如何在ASP.NET中使用DateTimeLocal
格式的文本框。根据具体的情况,您可能需要适当地调整代码。