MVC Extension with Scaffolding

2 posts, 0 answers
  1. Emad
    Emad avatar
    1 posts
    Member since:
    Aug 2013

    Posted 11 Mar 2015 Link to this post


    I created a new project via the Telerik MVC template. When using Scaffolding to generate a controller and view for an EF domain, if there is a datetime field it'll be mapped to a Telerik DateTimePicker somehow as code in the razor view will look like this code, where at run time with 'view source' I can see the KendoUi control mentioned. My question is how to access the datetimepicker for example to add events?


    <div class="form-group">
        @Html.LabelFor(model => model.from_date, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.from_date, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.from_date, "", new { @class = "text-danger" })


  2. Dimiter Madjarov
    Dimiter Madjarov avatar
    2122 posts

    Posted 13 Mar 2015 Link to this post

    Hello Emad,

    By default the UI for ASP.NET MVC Project includes built in editor templates using Kendo UI widgets. You could find them in the Views/Shared/EditorTemplates folder of the project. One approach to attach an event would be to directly modify the desired editor template for the specific type e.g. DateTime.

    @model DateTime?
    @(Html.Kendo().DateTimePickerFor(m => m)
          .Events(e => e.Open("onOpen"))
        function onOpen(e) {

    Another approach would be to leave the template as is and manually attach the event only for the current page. For example add the following script to the Edit view.
    $("#from_date").data("kendoDateTimePicker").bind("open", function(){

    Dimiter Madjarov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. UI for ASP.NET AJAX banner
Back to Top