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

Create function not working with multiselect in grid

1 Answer 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Evan
Top achievements
Rank 1
Evan asked on 08 Jan 2019, 10:57 AM

I'm getting a "ReferenceError: Roles is not defined" in the javascript when I try to add a new record. It all works well for existing ones.

 

Please see info here https://stackoverflow.com/questions/54089911/create-toolbar-function-not-working-with-multiselect-in-teleris-grid-for-mvc

 

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 10 Jan 2019, 09:09 AM
Hello Evan,

When a new item is created the fields in it will use the default values initially. It seems that the default value for Roles is IdentityRole. However, Roles is a collection. Try modifying the DataSource Model like this:


.Model(model =>
{
    model.Id(p => p.UserName);
    model.Field(p => p.AccessFailedCount).Editable(false);
    model.Field(p => p.Roles).DefaultValue(new List<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>());
})

Also, a collection should be passed to the MultiSelect editor. Since the MultiSelect will edit specific field you can use the MultiSelectFor syntax:


@model ICollection<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>
 
@(Html.Kendo().MultiSelectFor(m => m)
    .DataTextField("Name")
    .DataValueField("Id")
    .BindTo((System.Collections.ICollection)ViewData["roles"])
)


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Evan
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or