nicemanish
asked on
search button click show table
Hi Expert,
code is attached.
i want that when my form is loaded then only search form visible to user(means only ui show to user),' and when user click on search button then the grid table display the result.
in this code on form load its showing the records in the grid. please suggest how we can
do it
////code
controller
///
///////////
table script
code is attached.
i want that when my form is loaded then only search form visible to user(means only ui show to user),' and when user click on search button then the grid table display the result.
in this code on form load its showing the records in the grid. please suggest how we can
do it
////code
@model IEnumerable<MVCDemo.Models.Employee>
@{
ViewBag.Title = "Index";
}
<div style="font-family:Arial">
<h2>Employee List</h2>
<p>
@using (@Html.BeginForm("Index", "Home", FormMethod.Get))
{
<b>Search By:</b>
@Html.RadioButton("searchBy", "Name", true) <text>Name</text>
@Html.RadioButton("searchBy", "Gender") <text>Gender</text><br />
@Html.TextBox("search") <input type="submit" value="search" />
}
</p>
<table border="1">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Gender)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>Action</th>
</tr>
@if (Model.Count() == 0)
{
<tr>
<td colspan="4">
No records match search criteria
</td>
</tr>
}
else
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Gender)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
}
</table>
</div>
///controller
///
public ActionResult Index(string searchBy, string search)
{
if (searchBy == "Gender")
{
return View(db.Employees.Where(x => x.Gender == search || search == null).ToList());
}
else
{
return View(db.Employees.Where(x => x.Name.StartsWith(search) || search == null).ToList());
}
}
///////////
table script
Create table tblEmployee
(
ID int identity primary key,
Name nvarchar(50),
Gender nvarchar(10),
Email nvarchar(50)
)
Insert into tblEmployee values('Sara Nani', 'Female', 'Sara.Nani@test.com')
Insert into tblEmployee values('James Histo', 'Male', 'James.Histo@test.com')
Insert into tblEmployee values('Mary Jane', 'Female', 'Mary.Jane@test.com')
Insert into tblEmployee values('Paul Sensit', 'Male', 'Paul.Sensit@test.com')
Your question doesn't quite make sense. You are showing code, but it doesn't help explain what you are asking about.
ASKER
Its Straight forward.
From my code when page is loded then its showing me the result in table(grid) without any search.which i dont want.
i want when page load only UI display and when user put any criteria in text box and click search button that case its show result on table(grid).
hope its clear
From my code when page is loded then its showing me the result in table(grid) without any search.which i dont want.
i want when page load only UI display and when user put any criteria in text box and click search button that case its show result on table(grid).
hope its clear
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Its look like that I have to find answer from myself.once u will get it post to people how to do it.
"Its look like that I have to find answer from myself"
What does that mean? Does that mean that you think that my answer was not good enough, not detailed enough. I am perfect happy if you do find your own answer. I feel that it is my task to help you find your own answer.
ASKER
Thanks bob
I respect you,you have taken my comment otherwise,sorry if I hurt you,
My intension was only that I did not get perfect solution. Its
look like that I have create other view with post option or use partial view.plz don't mine .if I will get perfect solution I will post to u.
Thanks a lot for ur cooperation
I respect you,you have taken my comment otherwise,sorry if I hurt you,
My intension was only that I did not get perfect solution. Its
look like that I have create other view with post option or use partial view.plz don't mine .if I will get perfect solution I will post to u.
Thanks a lot for ur cooperation
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
done
ASKER