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

Value of Multiselect contains System.Collections.Generic.List`1[System.Int32] instead of array of int

0 Answers 64 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Ruslan
Top achievements
Rank 1
Ruslan asked on 16 Sep 2015, 06:14 AM

I have some model with selected ids:

class Model{
     public IList<int> SelectedIds { get; set; }
}

in my partial view I render Multiselect control:

@(Html.Kendo().MultiSelectFor(f => f.SelectedIds)
  .Name("SelectedIds")
  .Placeholder("​Select Items...")
  .Filter(FilterType.Contains)
  .IgnoreCase(true).TagMode(TagMode.Single)
  .TagTemplate("<span>​Selected #=data.dataItems.length# ​from #=data.maxTotal#</span>")
  .DataSource(a => a.Read("Get​ItemsListAction", "​Controller"))
  .DataValueField("Id")
  .DataTextField("Value")
  .AutoClose(false)
)

and it renders next wrong Javascript code (see value of the "value" at the end of the expression :):

jQuery(function(){jQuery("#SelectedIds").kendoMultiSelect({"dataSource":{"transport":{"read":{"url":"/sspd/​Controller/Get​ItemsListAction"},"prefix":""},"schema":{"errors":"Errors"}},"dataTextField":"Value","filter":"contains","ignoreCase":true,"tagMode":"single","tagTemplate":"\u003cspan\u003e​Selected#=data.dataItems.length# ​from #=data.maxTotal#\u003c/span\u003e","autoClose":false,"dataValueField":"Id","placeholder":"Select Items...","value":["System.Collections.Generic.List`1[System.Int32]"]});});

BUT!

When I change the Name in Razor code to something other name, for example, "bla-bla-bla" it renders correct code and I see in the web page multiselect with selected items:

jQuery(function(){jQuery("#bla-bla-bla").kendoMultiSelect({"dataSource":{"transport":{"read":{"url":"/sspd/​Controller/Get​ItemsListAction"},"prefix":""},"schema":{"errors":"Errors"}},"dataTextField":"Value","filter":"contains","ignoreCase":true,"tagMode":"single","tagTemplate":"\u003cspan\u003eSelected#=data.dataItems.length# from #=data.maxTotal#\u003c/span\u003e","autoClose":false,"dataValueField":"Id","placeholder":"Select Items...","value":[28620,32216]});});
 

In other words, rendered javascript is incorrect when Model's property for the selected ids is the same with parameter value passed to Html.Kendo().MultiSelect().Name method

Whats wrong in my code?

No answers yet. Maybe you can help?

Tags
MultiSelect
Asked by
Ruslan
Top achievements
Rank 1
Share this question
or