I currently have a dropdown list with Virtualization which shows the dropdowns as follows "First Middle Last (XXX-XX-XXXX)". When typing in the seach box I can successfully search based on name or SSN with dashes. However I would like to be able to search on SSN without dashes. I tried attaching another property to the viewmodel sent from the lookup controller but am unable to figure out how to achieve what I want while still preserving the dashes in the UI. My thought was to catch the filter and apply regex on it serverside that if only number had been entered then to add dashes after 3rd and 5th character which would allow me get my desired output.
Here is the View:
01.@Html.LabelFor(model => model.VisitorID)02. @(Html.Kendo().DropDownList()03. .Name("VisitorID")04. .DataTextField("Value")05. .DataValueField("ID")06. .MinLength(2)07. .HtmlAttributes(new { style = "width:100%" })08. .Height(290)09. .Filter(FilterType.Contains)10. .DataSource(source =>11. {12. source.Custom()13. .ServerFiltering(true)14. .ServerPaging(true)15. .PageSize(80)16. .Type("aspnetmvc-ajax") //Set this type if you want to use DataSourceRequest and ToDataSourceResult instances17. .Transport(transport =>18. {19. transport.Read("Virtualization_GetVisitor", "Lookups");20. })21. .Schema(schema =>22. {23. schema.Data("Data") //define the [data](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data) option24. .Total("Total"); //define the [total](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total) option25. });26. })27. .Virtual(v => v.ItemHeight(26).ValueMapper("VisitorLookups"))28. .NoDataTemplate("<a onclick=\"addNewEntityPartial(\'Visitor\');\">Add a new Visitor</a>")29. )30. @Html.ValidationMessageFor(model => model.VisitorID)
The C# For virtualization:
01.#region VisitorLookup02. public ActionResult Virtualization_GetVisitor([DataSourceRequest] DataSourceRequest request)03. {04. return Json(GetVisitor().ToDataSourceResult(request));05. }06. public ActionResult Visitor(int[] values)07. {08. var indices = new List<int>();09. 10. if (values != null && values.Any())11. {12. var index = 0;13. 14. foreach (var visitor in GetVisitor())15. {16. if (values.Contains(visitor.ID))17. {18. indices.Add(index);19. }20. 21. index += 1;22. }23. }24. return Json(indices, JsonRequestBehavior.AllowGet);25. }26. 27. private IQueryable<LookupViewModel> GetVisitor()28. {29. var ro = User.IsInRole("ReadOnly");30. return db.Visitors.Select(visitor => new LookupViewModel31. {32. ID = visitor.ID,33. Value = (visitor.Flag == true ? "FLAGGED " : "") +34. visitor.FirstName + " " +35. visitor.MiddleName + " " +36. visitor.LastName +37. " (" + (ro ? "XXX-XX-XXXX" : visitor.SSN.Replace("-", "")) + ") " +38. (visitor.Flag == true ? "FLAGGED" : ""),39. SSN = (ro ? "XXX-XX-XXXX" : visitor.SSN.Replace("-", ""))40. });41. }42. #endregion
I feel like I'm very close but am not quite sure how to modify the filter in the request on line 4 (second snippet) to achieve what i want.
Below was the path I was on:
01.public ActionResult Virtualization_GetVisitor([DataSourceRequest] DataSourceRequest request)02. {03. Regex regex = new Regex(@"[\d]");04. foreach (var filter in request.Filters)05. {06. if (regex.IsMatch(((FilterDescriptor)filter).ConvertedValue.ToString()))07. {08. 09. if (((FilterDescriptor)filter).Value.ToString().Length > 2)10. {11. ((FilterDescriptor)filter).Value.Insert(2, "-");12. }13. if (((FilterDescriptor)filter).Value.ToString().Length > 4)14. {15. ((FilterDescriptor)filter).Value.Insert(4, "-");16. }17. }18. }19. return Json(GetVisitor().ToDataSourceResult(request));20. }But that does not compile since Insert can't be made on a Object.
Any help?
