Format Date On Binding (ASP.NET MVC)

后端 未结 12 722
感情败类
感情败类 2021-01-31 08:46

In my ASP.net MVC app I have a view that looks like this:

...

<%=Html.TextBox(\"due\")%>
...

I am usi

12条回答
  •  清酒与你
    2021-01-31 09:05

    It's a dirty hack, but it seems to work.

    <%= Html.TextBoxFor(model => model.SomeDate,
        new Dictionary { { "Value", Model.SomeDate.ToShortDateString() } })%>
    

    You get the model binding, and are able to override the HTML "value" property of the text field with a formatted string.

提交回复
热议问题