Problem with CustomEditor

2 posts, 0 answers
  1. AKROS
    AKROS avatar
    68 posts
    Member since:
    Oct 2011

    Posted 05 Nov 2016 Link to this post

    I created a custom editor for my Scheduler, which works well.

    Then, I wanted to hide some parts of it with the help of a flag on my ViewModel like this:

    <div class="k-edit-label">
    @(Html.LabelFor(model => model.Title))
    <div data-container-for="title" class="k-edit-field">
    @(Html.TextBoxFor(model => model.Title, new { @class = "k-textbox", data_bind = "value:title" }))

    if(@Model.XXX) {

    <div class="k-edit-label">
    @(Html.LabelFor(model => model.Description))
    <div data-container-for="description" class="k-edit-field">
    @(Html.TextAreaFor(model => model.Description, new { @class = "k-textbox", data_bind = "value:description", rows = 3 }))

    But that didn't work. A debugging session shown that my XXX flag was always false. Curiously, if I'm writing something like this

    <div data-container-for="xxx" class="k-edit-field">
    @(Html.TextBoxFor(model => model.XXX, new { @class = "k-textbox", data_bind = "value:xxx" }))

    I'm seeing the correct value (something true, something false).
    So my question is: why using @Model.XXX always return false (the default value of a flag) and how then to implement the behavior I would like?
    Thanks & Cheers,


  2. Bozhidar
    Bozhidar avatar
    1142 posts

    Posted 08 Nov 2016 Link to this post


    The Editor template is not evaluated on the server. It's used to create a client declaration, that's used by the Scheduler client widget when an event is edited. The if statement is therefore evaluated on the server, where the boolean variable is not bound to any event, and will always return the default value for boolean - false.

    If you want to show/hide elements based on what event is loaded, you can use the edit event and use jQuery to access the elements:

    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top