Problem with CustomEditor

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

    Posted 05 Nov 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>
    <div data-container-for="title" class="k-edit-field">
    @(Html.TextBoxFor(model => model.Title, new { @class = "k-textbox", data_bind = "value:title" }))
    </div>

    if(@Model.XXX) {

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

    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" }))
    </div>

    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,

    Nicolas

  2. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 08 Nov Link to this post

    Hi,

    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:
    http://docs.telerik.com/kendo-ui/api/javascript/ui/scheduler#events-edit

    Regards,
    Bozhidar
    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.
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top