Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @(Html.Kendo().DropDownList()
- .Name("VesselId")
- .OptionLabel("Please select")
- .DataTextField("Name")
- .DataValueField("VesselId")
- .MinLength(3)
- .Filter(FilterType.Contains)
- .DataSource(source =>
- {
- source.Custom()
- .ServerFiltering(true)
- .ServerPaging(true)
- .PageSize(80)
- .Type("aspnetmvc-ajax")
- .Transport(transport =>
- {
- transport.Read("ReadVessels", "Report");
- })
- .Schema(schema =>
- {
- schema
- .Data("Data")
- .Total("Total")
- .Errors("Errors");
- });
- })
- .Virtual(v => v
- .ItemHeight(30)
- .ValueMapper("valueMapper")
- ))
- public ActionResult VesselsValueMapper(int[] values)
- {
- var indices = new List<int>();
- if (values != null && values.Any())
- {
- var index = 0;
- foreach (var vessel in GetMapperVessels())
- {
- if (values.Contains(vessel.VesselId))
- {
- indices.Add(index);
- }
- index += 1;
- }
- }
- return Json(indices, JsonRequestBehavior.AllowGet);
- }
- private static IEnumerable<Vessel> GetMapperVessels()
- {
- var data = new UnitOfWork();
- var vessels = data.VesselRepository.Get();
- return vessels;
- }
- function valueMapper(options) {
- $.ajax({
- url: "@Url.Action("VesselsValueMapper", "Report")",
- data: convertValues(options.value),
- success: function (data) {
- console.log("Value Mapper Success")
- options.success(data);
- console.log(data);
- }
- });
- }
- function convertValues(value) {
- var data = {};
- value = $.isArray(value) ? value : [value];
- for (var idx = 0; idx < value.length; idx++) {
- data["values[" + idx + "]"] = value[idx];
- }
- return data;
- }
- foreach (var vessel in GetMapperVessels())
- {
- if (values.Contains(vessel.VesselId))
- {
- indices.Add(index);
- }
- index += 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement