Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:38:24+00:00 2026-05-31T07:38:24+00:00

My Datetime picker is working fine for Html.TextBoxFor but when i have Html.EditorFor it

  • 0

My Datetime picker is working fine for “Html.TextBoxFor” but when i have “Html.EditorFor” it is not showing anydatepicker.

i have a Jquery as follows:

  $(document).ready(function () {
               $('.dp').datepicker({
                   changeMonth: true,
                   changeYear: true,
                   dateFormat: 'yy-mm-dd'
               });
           }); 

I want to use this function in my .aspx page.

 <div class="float-left">
 <%: Html.Label("BAASent Date") %>
 <br />
 <%:Html.TextBoxFor(model => model.BAASentDate, new { @class = "dp" }) %>
 <%: Html.ValidationMessageFor(model => model.BAASentDate) %>
 </div> 

for the above code everything works fine.
but when i replace “Html.TextBoxFor” with “Html.EditorFor”,it is not displaying any datetime picker.

whats going wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:38:25+00:00Added an answer on May 31, 2026 at 7:38 am

    When you use EditorFor you probably do not apply the dp class to the corresponding input field and so the $('.dp') selector that you are using for your deatepicker returns nothing.

    One possibility is to apply the class to the parent div:

    <div class="float-left dp">
        <%= Html.Label("BAASent Date") %>
        <br />
        <%= Html.EditorFor(model => model.BAASentDate) %>
        <%= Html.ValidationMessageFor(model => model.BAASentDate) %>
    </div>
    

    and then adjust your selector so that you fetch the input field that’s inside the div with the given classname:

    $(document).ready(function () {
        $('.dp :input').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd'
        });
    });
    

    Another possibility is to write a custom editor template for the DateTime field in which you would apply the dp class to the TextBox. So inside ~/Views/Shared/EditorTemplates/DateTime.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <%= Html.TextBox(
        "", 
        ViewData.TemplateInfo.FormattedModelValue,
        new { @class = "text-box single-line dp" }
    ) %>
    

    and then:

    <div class="float-left">
        <%= Html.Label("BAASent Date") %>
        <br />
        <%= Html.EditorFor(model => model.BAASentDate) %>
        <%= Html.ValidationMessageFor(model => model.BAASentDate) %>
    </div>
    

    and finally:

    $(document).ready(function () {
        $('.dp').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd'
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox with jquery ui datetime picker. When i open the page
I cant get the datetime picker working. In the layout partial I have <script
i have this code for a datetime picker <link type=text/css href=css/ui-lightness/jquery-ui-1.7.2.custom.css rel=stylesheet /> <script
I am using jquery datetime picker. it is showing date in yy/MMM/dd hh:mm:ss format
I'm using MVC2 and have included the Jquery DateTime picker. For some reason it
I have one issue with Datetime Picker In my firstview i have button.If i
I've been having problems with Jquery Datetime picker. The slider wouldn't work on touch
I have a a couple of datetime picker fields and if any of them
I have a datetime picker in one of our apps. When loading up the
I used different jQuery plugins and in some cases they were not working properly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.