Reputation: 7163
I have a textbox on my view and I'm only looking it to display the current date and time(in readonly..how can this be done?
Currently I have this in the view:
<div class="editor-field">
@Html.EditorFor(model => model.Opened, new { @value = System.DateTime.Now, @readonly = "readonly" })
@Html.ValidationMessageFor(model => model.Opened)
</div>
..And this in the model:
[Required]
public DateTime Opened
{
get;
set;
}
How can this be implemented in MVC?
Thanks,
Upvotes: 2
Views: 1805
Reputation: 3434
Well, you can do that, but @Angel Manuel Garcia Car's suggest is what you should be doing logically.
Anyways, here is the code. As long as you are creating a textbox, you should be using TextBoxFor
.
@Html.TextBoxFor(model => model.Opened, new { @value = DateTime.Now, @readonly="readonly" })
I don't see any point here.
Upvotes: 1
Reputation: 85
I recommend you using a Label. I think it's unusual display dates and time at TextBoxes.
Regards.
Upvotes: 2