This is a migrated thread and some comments may be shown as answers.

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

1 Answer 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gerard
Top achievements
Rank 1
Gerard asked on 12 Sep 2016, 12:41 PM

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.

1 Answer, 1 is accepted

Sort by
0
Gerard
Top achievements
Rank 1
answered on 13 Sep 2016, 02:52 PM
I figured it out. Thank you for your help:)
Tags
Grid
Asked by
Gerard
Top achievements
Rank 1
Answers by
Gerard
Top achievements
Rank 1
Share this question
or