Date display format of date on TextAreafor directly

I was wondering if there is a way to directly change the format of the date displayed in the TextAreaFor. I know this topic has been asked a lot and my problem may seem similar to these two:

MVC DateTime textbox formatting issue

How would you format the DateTime displayed by TextBoxFor () in MVC3?

But I will explain why this is different. Here's the textarefor:

@Html.TextAreaFor(m => m[i].DateFormation, new { @class = "textArea" })

      

As in the related questions above, I can put the DisplayFormat attribute on the field, but I am not allowed to change the model or use the metadata

So my question is, is there a way to apply the format to a text file, how can you do with a text box for?

@Html.TextBoxFor(m => m[i].DateFormation, "{0:yyyy-MM-dd}", new { @class = "textArea" })

      

I tried to apply .ToString

to my field but it looks like TextAreafor won't accept it

Note. My last random scenario is that I will have to modify the content of the model with C # code before showing it, but this is just wrong for me and bad practice for mixing my code with design

+3


source to share


1 answer


After searching differently and looking in the documentation (thanks @StephenMuecke for the hint) it TextAreaFor

just dosen't have any option that supports shaping so badly, just use the code before showing the date so that the time is not shown in the picture.

I looked at the big overload and parameter shown for textarea from this msdn link: https://msdn.microsoft.com/en-us/library/system.web.mvc.html.textareaextensions(v=vs.118).aspx



And as shown in the link, the only possible overload for TextAreaFor is model related and neither can accept the property change formatting

0


source







All Articles