Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. @Html.DropDownListFor(x => x.StudentId, Enumerable.Empty<SelectListItem>(),
  2. new { style ="width: 100%;" } )
  3.  
  4. $("#StudentId").select2({
  5. multiple: false,
  6. placeholder: "Select",
  7. allowClear: true,
  8. tags: true,
  9.  
  10. ajax: {
  11. url: '/Grade/StudentLookup',
  12. dataType: 'json',
  13. delay: 250,
  14.  
  15. data: function (params) {
  16. return {
  17. //q: params.Name, // search term
  18. //page: params.page
  19. query : 'test' //this parameter can be passed via AJAX
  20. //!!! but I cannot get the selected text or value of dropdownlist
  21. };
  22. },
  23.  
  24. processResults: function (data, page) {
  25. var newData = [];
  26. $.each(data, function (index, item) {
  27. newData.push({
  28. id: item.Id, //id part present in data
  29. text: item.Name //string to be displayed
  30. });
  31. });
  32. return { results: newData };
  33. },
  34. cache: true
  35. },
  36. escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
  37. minimumInputLength: 0, //for listing all, set : 0
  38. maximumInputLength: 20, // only allow terms up to 20 characters long
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement