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 8017253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:47:33+00:00 2026-06-04T20:47:33+00:00

I am fairly new to MVC3, and am building a SQL 2008 R2, EF4

  • 0

I am fairly new to MVC3, and am building a SQL 2008 R2, EF4 website with it. In the last 36 hours, I have attempted to add Telerik’s MVC extensions to the project in the hopes of using the DatePicker, Menu, etc. I believe that my configuration & installation are good, and some small tests (panel bar example) that I’ve done seem to confirm that, and my edits to the _layout.cshtml file also seem like they are good.

Where I’m stuck is attempting to integrate the Razor code examples for the Datepicker ( http://demos.telerik.com/aspnet-mvc/razor/datepicker ) to my existing project. I would like to add a Datepicker to a “date of birth” (DOB) field in my application’s Profile page. The Profile has a table in the database, a model (profile.cs), a controller (ProfileController.cs) and some views in a Views/Profile directory (Index, Edit, etc.) All of the examples seem to focus on creating entirely new projects, new models, new controllers, etc. and because of my relative inexperience, I’m a little stuck on how to use the demo code outlined in my existing project.

I am assuming that I can place this partial class into my ProfileController.

public partial class DatePickerController : Controller
{
    public ActionResult FirstLook(FirstLookModelView viewModel)
    {
        viewModel.DatePickerAttributes.SelectedDate = viewModel.DatePickerAttributes.SelectedDate ?? DateTime.Today;
        viewModel.DatePickerAttributes.MinDate = viewModel.DatePickerAttributes.MinDate ?? new DateTime(1900, 1, 1);
        viewModel.DatePickerAttributes.MaxDate = viewModel.DatePickerAttributes.MaxDate ?? new DateTime(2099,
            12, 31);
        viewModel.DatePickerAttributes.ShowButton = viewModel.DatePickerAttributes.ShowButton ?? true;
        viewModel.DatePickerAttributes.OpenOnFocus = viewModel.DatePickerAttributes.OpenOnFocus ?? false;
        return View(viewModel);
    }
}

And that I can put the View elements into my Edit.cshtml where my @Html.EditorFor(model => model.DOB) is now

@(Html.Telerik().DatePicker()
        .Name("DatePicker")
        .HtmlAttributes(new { id = "DatePicker_wrapper" })
        .Min(Model.DatePickerAttributes.MinDate.Value)
        .Max(Model.DatePickerAttributes.MaxDate.Value)
        .ShowButton(Model.DatePickerAttributes.ShowButton.Value)
        .Value(Model.DatePickerAttributes.SelectedDate.Value)
)

@using (Html.Configurator("The date picker should...")
              .PostTo("FirstLook", "DatePicker")
              .Begin())
   { 
    <ul>
        <li>
            @Html.CheckBox("DatePickerAttributes.ShowButton", Model.DatePickerAttributes.ShowButton.Value)
            <label for="DatePickerAttributes_ShowButton">show a popup button</label>
        </li>
   <snip>

But I am fairly confused about where to put the section of code for the model…

public class FirstLookModelView
{
    public FirstLookModelView()
    {
        DatePickerAttributes = new DatePickerAttributes();
    }
    public DatePickerAttributes DatePickerAttributes { get; set; }
}

Does that go into my current model Profile.cs? Any guidance would be appreciated.

PS I’m asking on the Telerik forums as well: http://www.telerik.com/community/forums/aspnet-mvc/documentation/difficulty-with-existing-project-and-adding-telerik-mvc-to-it.aspx

  • 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-06-04T20:47:35+00:00Added an answer on June 4, 2026 at 8:47 pm

    Thanks to a good friend of mine helping me out, and some support from Telerik, I got my answers. It could just be me, or perhaps their MVC support examples are actually confusing. Anyone who is trying to use Telerik’s MVC for the first time, that is an MVC newbie, I hope this helps you.

    I will assume that you have followed the tutorials on setting up Telerik MVC to work in your project, and are now where I was, struggling to implement one of their tools for the first time.

    First step, do not take the code examples here (http://demos.telerik.com/aspnet-mvc/razor/datepicker) like “view” “controller” and “_layout.cshtml” as the definitive code you will need to implement. Click on “edit template” (at least for this DatePicker example) and you will see much more code in the Razor examples: http://demos.telerik.com/aspnet-mvc/razor/datepicker/edittemplate

    You will have to adjust my examples to your actual code, but I’m going to stick to the example code that I posted in my original question. In your model (Profile.cs) file, amend the datetime field thusly:

        [UIHint("MyCustomEditorTemplate")]
        public Nullable<System.DateTime> DOB { get; set; }
    

    HINT: in your Using at the top of the model file, add this:

          using System.ComponentModel.DataAnnotations;
    

    The code snippets from my question for public partial class DatePickerController : Controller and also public class FireLookModelView go into the ProfileController (or rather, your controller.)

    Now make a new controller, called DatePickerController.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MySite.Controllers
    {
    public class DatePickerController : Controller
    {
    
    }
    public class DatePickerAttributes
    {
        public DateTime? SelectedDate
        {
            get;
            set;
        }
    
        public DateTime? MinDate
        {
            get;
            set;
        }
    
        public DateTime? MaxDate
        {
            get;
            set;
        }
    
        public bool? ShowButton
        {
            get;
            set;
        }
    
        public bool? OpenOnFocus
        {
            get;
            set;
        }
    }
    
    public class TimePickerAttributes
    {
        public DateTime? SelectedDate
        {
            get;
            set;
        }
    
        public DateTime? MinTime
        {
            get;
            set;
        }
    
        public DateTime? MaxTime
        {
            get;
            set;
        }
    
        public bool? ShowButton
        {
            get;
            set;
        }
    
        public int? Interval
        {
            get;
            set;
        }
    
        public bool? OpenOnFocus
        {
            get;
            set;
        }
    }
    
    public class DateTimePickerAttributes
    {
        public DateTime? SelectedDate
        {
            get;
            set;
        }
    
        public DateTime? MinDate
        {
            get;
            set;
        }
    
        public DateTime? MaxDate
        {
            get;
            set;
        }
    
        public int? Interval
        {
            get;
            set;
        }
    }
    }
    

    Under your Views, in the Shared directory, create a new sub-directory called EditorTemplates. Create an empty file there, call it DateTime.cshtml:

    @model DateTime?
    
    @(Html.Telerik().DateTimePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
        .Value(Model > DateTime.MinValue? Model : DateTime.Today)
    )
    

    Now go to the page where you want the datepicker to appear, in my case it was: Views/Profile/Edit.cshtml:

    Replace the HTML.EditorFor with this:

    @Html.Telerik().DatePickerFor(model => model.DOB)
    

    ..and those are actually all the pieces you need (I believe) to setup your first actual working tool with Telerik MVC. Hope this helps whomever finds this!

    Ed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to unit testing. I am building an ASP.NET MVC3 application
Fairly new to asp.net Mvc and jquery. Have the following code working fine, but
Hi fairly new to using MVC radio buttons. I have some code: @Html.RadioButtonFor(modelItem =>
fairly new iPhone developer here. Building an app to send RS232 commands to a
I am new to fairly new to AS3 and I have found myself needing
I am fairly new to C++ and I have seen a bunch of code
I am fairly new to Rails and I have never developed a large application.
Fairly new to MVC3 and I am doing a simple project for testing purposes.
Fairly new to CodeIgniter, still grasping the MVC approach. I'm just wondering what's the
Being fairly new to C++ I have a question bascially concerning the g++ compiler

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.