How to bind model with complex type and use a multivalue column to update model

2 posts, 0 answers
  1. Gerard
    Gerard avatar
    2 posts
    Member since:
    Nov 2015

    Posted 12 Sep Link to this post

    Hello,

    I have model that looks like

     public class VacUserSecurityModel
        {
            private bool isCurrentUser;

            public VacUserSecurityModel()
            {
                this.Claims = new List<UserClaim>();
            }    

            public string Id { get; set; }
            public string Email { get; set; }
            public string UserName { get; set; }
            [UIHint("ClaimsEditor")]
            public List<UserClaim> Claims { get; set; }
        }

    Here is a grid 

    @(Html.Kendo().Grid<VacUserSecurityModel>
        ()

        .Name("allGrid")
        .DataSource(datasource => datasource.Ajax().Read(read => read.Action("ReadAllUserClaims", "Authorization"))
        .Update(update => update.Action("UpdateUserClaims", "Authorization"))
        .Model(model =>
        {
            model.Id(p => p.Id);
            model.Field(p => p.UserName).Editable(false);
            model.Field<List<UserClaim>>(e => e.Claims);
        }))
        .NoRecords(x => x.Template("<div class='k-grid-norecords-template'>No records</div>"))
        .Editable(editable => editable.Mode(GridEditMode.PopUp))
        .HtmlAttributes(new { style = "height:550px;" })
        .Columns(columns =>
        {
            columns.Bound(c => c.Id).Visible(false).Title("ID");
            columns.Bound(c => c.UserName).Width(250).Title("User");
            columns.Bound(c => c.Claims).ClientTemplate("#=claimsTemplate(Claims)#");
            columns.Command(commands => { commands.Edit(); });
        })
    )

    Claims Editor:

    @model  Models.Authorization.VacUserSecurityViewModel
    @(Html.Kendo().MultiSelect()
        .Name("RoleClaims")
        .Placeholder("Select roles")
        .DataTextField("ClaimValue")
        .DataValueField("ClaimValue")
        .BindTo((System.Collections.IEnumerable) ViewData["RolesDictionary"]))

    How do I need to change the grid definition to bind Claims property to be able to edit this collection? During update, Claims property has old values regardless what I select.

    Any help will be appreciated.

  2. Gerard
    Gerard avatar
    2 posts
    Member since:
    Nov 2015

    Posted 13 Sep in reply to Gerard Link to this post

    I figured it out. Thank you for your help:)
  3. Kendo UI is VS 2017 Ready
Back to Top