Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 帮助用户在EditFor中输入正确的格式_C#_Sql Server_Asp.net Mvc - Fatal编程技术网

C# 帮助用户在EditFor中输入正确的格式

C# 帮助用户在EditFor中输入正确的格式,c#,sql-server,asp.net-mvc,C#,Sql Server,Asp.net Mvc,我的SQL数据库有一个列Date,它只允许以下格式的字符串:\uuuuuuuuuuuuuuuuu,基本上是月/年,例如:01/2019 我的: @Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control" } }) 是否有一些助手,以便用户只能使用正确的格式键入?例如,编辑器的强类型如下:\uuuuu/\uuuuuuuuu,并且只能输入数字来填充下划线。如果您将数据库和模

我的SQL数据库有一个列
Date
,它只允许以下格式的字符串:
\uuuuuuuuuuuuuuuuu
,基本上是月/年,例如:
01/2019

我的:

@Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control" } })

是否有一些助手,以便用户只能使用正确的格式键入?例如,编辑器的强类型如下:
\uuuuu/\uuuuuuuuu
,并且只能输入数字来填充下划线。

如果您将数据库和模型更改为存储日期而不是字符串(无论如何我都会建议),我认为您可以在中使用该技术。用户界面和数据存储中字段的数据格式可以是独立的。您应该在用户区域设置中显示日期,并在保存到数据库之前转换为格式。这是否有帮助:
?()@Alex不太可能,因为SQL以这种格式将值存储为nvarchar。@GarethD如果我将数据类型更改为
DateTime
,我是否能够使用@Alex方法输入
month
@Html.TextBoxFor(m => m.StartDate, 
    new { @Value = Model.StartDate.ToString("yyyy/MM/dd"), @class="datepicker" })