Search code examples
asp.net-corekendo-uitelerikbegincollectionitem

asp.net core Begin Collection Item core not working with kendo controls


I have used BeginCollectionItem in asp.net core. Inside this collection I have used kendo combobox and datepicker both data not bind with model list when post the data. anyone have idea about it.

Below is the code sample for cshtml file

@using HtmlHelpers.BeginCollectionItemCore
    @using DemoProject.Model
    @model BatchDetail
    
    
    <tr data-rownum="@Model.Seq">
        @using (Html.BeginCollectionItem("oBatchDetails"))
        {           
            <td>                
            @Html.EditorFor(model => model.CheckCardNo, new { htmlAttributes = new { @class = "form-control input-sm patientCheckCard clsAlphaNumericText", maxlength = "50", autocomplete = "off" } })
            </td>
            <td>
            @(Html.Kendo().DatePickerFor(model => model.CheckDate).Format("MM/dd/yyyy").HtmlAttributes(new { style = "width:115px", @class = "smalldtpicker paidDate", autocomplete = "off", @type = "" }))
          </td>            
        }
    </tr> 

When I see the $("#formid").serialize() in console. I found the below result.

oBatchDetails%5B25e11650-70cd-4d04-9fe0-4ce0e621cbfd%5D.CheckCardNo=123456789&
CheckDate=12%2F27%2F2021&

where check date should be oBatchDetails%5B25e11650-70cd-4d04-9fe0-4ce0e621cbfd%5D.CheckDate=12%2F27%2F2021&

but Begin collection item not handle this kendo datepicker.


Solution

  • I found the solution for kendo control. to resolve this issue need to call render function to work with kendo controls. Got the reference from https://www.telerik.com/forums/datepicker-error-with-core-5-0

    below is the corrected code and it is working fine with begin collection item core.

     @using HtmlHelpers.BeginCollectionItemCore
            @using DemoProject.Model
            @model BatchDetail
            
            
            <tr data-rownum="@Model.Seq">
                @using (Html.BeginCollectionItem("oBatchDetails"))
                {           
                    <td>                
                    @Html.EditorFor(model => model.CheckCardNo, new { htmlAttributes = new { @class = "form-control input-sm patientCheckCard clsAlphaNumericText", maxlength = "50", autocomplete = "off" } })
                    </td>
                    <td>
                    @{
                       Html.Kendo().DatePickerFor(model => model.CheckDate).Format("MM/dd/yyyy").HtmlAttributes(new { style = "width:115px", @class = "smalldtpicker paidDate", autocomplete = "off", @type = "" }).Render();
                     }
                  </td>            
                }
            </tr>