2

I need to specify an @Html.EditorFor view element in some jQuery code I'm using (datepicker). Is it possible to give a specific EditorFor element a name or id?

    <div class="editor-field">
        @Html.EditorFor(model => model.DateTaken)
        @Html.ValidationMessageFor(model => model.DateTaken)
    </div>

1 Answer 1

3

I am assuming that your datepicker is being used on a text field? Also assuming that by 'EditorMessageFor,' you mean EditorFor.

If both of my assumptions are correct, you can use TextBoxFor instead, like so:

@Html.TextBoxFor(m => m.DateTaken, new { id = "MyCssId" })

Failing that, you'd have to create a custom editor template. There's a comprehensive guide to doing just that here.

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.