Pre-populating fields in a text field using MVC / jQuery

I recently went through a project trying to misinform several data inputs (most of them mostly Dates (mm/dd/yyyy)or DateTimes (mm/dd/yyyy hh:mm:ss am/pm).

I am using the DigitalBush Masking Plugin plugin and everything seemed to work the same way as with empty fields. However, when I tried to apply the masked field to the field that was bound to the ViewModel, I seemed to run into problems.

Example:

HTML:

<%= Html.TextBoxFor(model => model.DateOfBirth})%>

JQuery

$("#DateOfBirth").mask("99/99/9999",{placeholder:" "});

I was curious if anyone had any ideas on how to mask a text field in a field that was previously populated with data from the ViewModel so that it looked as usual, but when it changed, it reacts like a masked input.

+3
1

:

<%= Html.TextBoxFor(model => model.DateOfBirth) %>

:

<%= Html.EditorFor(model => model.DateOfBirth) %>

[DisplayFormat]:

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime DateOfBirth { get; set; }
+5

All Articles