Reputation: 9
I am having an issue with search/filter. I have a list (user details - pic,name) and I use html helper editorformodel to display the list, I would like to incorporate search for the list, as I type in each letter I would like the list to display the matching items from the list without going back to controller. Is this possible?
I have seen some posts like Asp.Net MVC3 adding search functionality but they go back to controller
I am new to MVC, Please help.
Indira
Edit(additional info):
Here's what I was doing, I am passing a model(there are two lists and two strings) from controller to view, using Editorformodel() in view and creating partialview for model. In the partialview I display two lists( which in turn are models containing name,picture url ,bool value). I need to search through this list for matching string from the username's as we type in letters, and select those elements to pass to the model. Example:
public class myuser
{string name;string picture_url; bool selected;}
public class mylibrary
{string name; IEnumerable<myuser> userlist; IEnumerable<myuser> adminuser; string deadline;}
controller{...... return view(mylibrary);}
In the model @model ....models.mylibrary . . . @using(Html.BeginForm(....) { @Html.EditorForModel() }
Partial view for mylibrary
@model ....models.mylibrary
@Html.EditorFor(x=>x.userlist) ---this is the list I want to search through
@Html.EditorFor(x=>x.adminuser)
@Html.TextBoxFor(x=>x.deadline)
partial view for myuser
@model .....models.myuser
@html.Checkboxfor(x=>x.selected)
@html.LabelFor(x=>x.Name)
I am not using any table to display, it's all html. I'd like to modify the list on every keystroke and return the updated list and that's were I'm struggling. Please let me know if you need more detail, and thanks again for the help.
Upvotes: 0
Views: 631
Reputation: 19847
Select To Autocomplete is a good jQuery plugin for achieving this functionality. It requires only a single line to turn a select list into an autocompletable input
$('select').selectToAutocomplete();
Upvotes: 1