1

I've created a custom EditorFor DateTime and added a classname to the textbox

@model DateTime
@Html.TextBoxFor(m => m, new {  @class = "date-time-picker" })

So that I can connect jquery datepicker to it client side

$("input.date-time-picker").datetimepicker();

The problem is that for the

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:g}")]

attribute to work you need to use the built in EditorFor (Or extracting the model metadata and do the same stuff yourself), so whats the best way of overriding the default EditorFor, add the classname and call the built in editorfor so that I can use the DisplayFormat attribute

2
  • Try to use a UIHint DataAnnotation for your property. Maybe it can work. Commented Oct 12, 2011 at 11:33
  • How exactly? I know that you can use it to specify which view to use.. But how does this help here? Commented Oct 12, 2011 at 12:01

1 Answer 1

1

(Question answered by the OP in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

I solved it by doing this, but it feels like reinventing the wheel

@model DateTime  
@Html.TextBox("", string.Format(ModelMetadata.FromLambdaExpression(x => x, ViewData).DisplayFormatString, Model), new { @class = "date-time-picker" })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.