This is Most important thing to change without this search function does not work
Without this they does not find the string that you will search
And show Like this in your url localhost:7276/HomePage/Index?
First i use this
<input class="form-control" type="text" placeholder="Search for..." aria-label="Search" aria-describedby="btnNavbarSearch" />
Second i use this
<input class="form-control" type="text" placeholder="Search for..." name="SearchString" value="@ViewData["CurrentFilter"]" aria-label="Search" aria-describedby="btnNavbarSearch" />
<form method="get" action="/HomePage/Index" class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
<div class="input-group sty">
<input class="form-control" type="text" placeholder="Search for..." name="SearchString" value="@ViewData["CurrentFilter"]" aria-label="Search" aria-describedby="btnNavbarSearch" />
<input type="submit" value="Search" class="btn btn-primary" />
</div>
</form>
>Solution :
Based on your previous question, it seems that you are trying to
implement a search option at your nav bar. So you were missing this
two properties in your view.name="SearchString"
value="@ViewData["CurrentFilter"]".
How It works
When you submit the below
formit willsubmityouruser search inputwhich has been set toSearchStringasnameproperty. So at
your controller you will receive the value forstring searchString
which will filter your search result and return the new view
<form method="get" action="/Home/Index">
<td style="padding-right:760px">
</td>
<td>
<input class="form-control" type="text" placeholder="Search for..." name="SearchString" value="@ViewData["CurrentFilter"]" aria-label="Search" aria-describedby="btnNavbarSearch" />
</td>
<td>
<input type="submit" value="Search" class="btn btn-primary" />
</td>
</form>
Controller
if (!String.IsNullOrEmpty(searchString))
{
members = members.Where(m => m.Name.Contains(searchString)
|| m.Gender.Contains(searchString));
return View(members);
}
Note: Above submitted keys
name="SearchString"will be passed there and return the new view
Output
Hope now it is completely clear to you. and It will resolve your issue.
