I'm currently interning as part of my school course at a small tech company and one of the projects I'm working on right now is making a web application with MVC
.
The manager gave me a SQL database to work with and I've been following this tutorial by Microsoft here to help me build the web app.
Now, the specific thing the manager wants me to do is hiding the table when someone loads the page and when a string is submitted into the search bar, the relevant information in the table matching the string shows up.
I've been looking everywhere, including SO how to do this for a few days now, no matter what code I try it doesn't seem to work! I've been trying different things using HTML
and JS
, following some examples posted here, I just can't figure out how to do it, the table flashes for a second when I click the search button, I think it's the page refreshing but why?
Here's my controller with the searchBar
public ActionResult Index(string searchString)
{
ViewBag.NameSortParm = String.IsNullOrEmpty (searchString) ? "name_prmrnm" : "";
var person = from p in db.persons
select p;
if (!String.IsNullOrEmpty(searchString))
{
person = person.Where(s => s.name.Contains(searchString));
}
return View(person.ToList());
}
Here's my javascript in the View:
<script type="text/javascript">
function escondeTable(){
var hideTab = document.getElementById("table-class");
if (hideTab.style.display == 'none') {
hideTab.style.display = '';
}
else {
hideTab.style.display == 'none'
}
}
</script>
And here's my form:
<form action="/people/Index" method="post" onsubmit="escondeTable()">
<p class="barraProc">
@Html.TextBox("searchString", "", new { placeholder = "Insira um nome..." })
<input type="button" value="Procurar">
</p>
</form>
Can anyone tell me what I could be using or doing?