1
I’m having doubts in the creation of an item search box. I already say that I’m a beginner.
I want when the user type a name in the search box to appear the items that contain the name that the user typed or part of it, for example: the user typed materials or mat then you should show up:
- office supplies
- automotive materials
- etc....
My biggest question is how to implement this using DDD. I saw this example, and I found it relatively simple, but I can’t imagine a form of implementation. I saw that it implements Pagedlist.Mvc and found simple, but how to leave uncoupled (Using DDD)?
An example of what was implemented there
public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var students = from s in db.Students
select s;
if (!String.IsNullOrEmpty(searchString))
{
students = students.Where(s => s.LastName.Contains(searchString)
|| s.FirstMidName.Contains(searchString));
}
switch (sortOrder)
{
case "name_desc":
students = students.OrderByDescending(s => s.LastName);
break;
case "Date":
students = students.OrderBy(s => s.EnrollmentDate);
break;
case "date_desc":
students = students.OrderByDescending(s => s.EnrollmentDate);
break;
default: // Name ascending
students = students.OrderBy(s => s.LastName);
break;
}
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(students.ToPagedList(pageNumber, pageSize));
}
In my view, there is another way to do this to leave uncoupled.
Could you post your code? Only with this it is difficult to help you.
– Randrade
@Randrade I’m just with the textbox code ready. Nothing else.
– Iago Frota