C# 设置视图';s文本框(日期时间字段)以显示只读的当前日期时间

C# 设置视图';s文本框(日期时间字段)以显示只读的当前日期时间,c#,asp.net-mvc,asp.net-mvc-4,C#,Asp.net Mvc,Asp.net Mvc 4,我的视图上有一个文本框,我只是在查看它以显示当前的日期和时间(只读)。如何才能做到这一点 目前我的观点是: <div class="editor-field"> @Html.EditorFor(model => model.Opened, new { @value = System.DateTime.Now, @readonly = "readonly" }) @Html.ValidationMessageFor(model =>

我的视图上有一个文本框,我只是在查看它以显示当前的日期和时间(只读)。如何才能做到这一点

目前我的观点是:

    <div class="editor-field">
        @Html.EditorFor(model => model.Opened, new { @value = System.DateTime.Now, @readonly = "readonly" })
        @Html.ValidationMessageFor(model => model.Opened)
    </div>
如何在MVC中实现这一点


谢谢,

我建议您使用标签。我认为在文本框中显示日期和时间是不寻常的


问候。

好吧,你可以这样做,但是@Angel Manuel Garcia Car的建议是你应该做的合乎逻辑的事情

不管怎样,这是代码。只要您创建一个文本框,就应该使用
TextBoxFor

@Html.TextBoxFor(model => model.Opened, new { @value = DateTime.Now, @readonly="readonly" })

我看不出这有什么意义。

使用
标签在语义上不正确,因为标签定义了元素的标签。@StephenMuecke,如果不是ASP.NET标签(),我不建议使用HTML标签。
@Html.TextBoxFor(model => model.Opened, new { @value = DateTime.Now, @readonly="readonly" })