I've got a model with a DateOfBirth
property on it, and in the view that uses that model, I've got a textbox:
Html.TextBox("DateOfBirth")
I'm using DataAnnotations on the model, and validation works properly, and the textbox's value is loaded from the model. However, I don't want that value to be what is initially displayed, but rather its ToShortDate()
value. But I can't seem to override the model's value. Even if I put "ASDF" as the value parameter of the TextBox
method, the model's value is what ends up in the text box. I've also tried using a [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d")]
attribute, but that didn't help, either.
So how can I override the model's value with its To开发者_开发技巧ShortDate()
value?
It looks like there's not a good way around this. Perhaps specifying an HTML attribute to override, but the inline HTML is good enough for now. I'd welcome an alternative, though.
精彩评论