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
@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> 

Open in new window

///

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());
    }
}

Open in new window


///////////
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')

Open in new window

nicemanishAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nicemanishAuthor Commented:
Admin plz look and provide help
0
Bob LearnedCommented:
Your question doesn't quite make sense.  You are showing code, but it doesn't help explain what you are asking about.
0
nicemanishAuthor Commented:
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
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Bob LearnedCommented:
Is this the code for the view?

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());
    }
}

Open in new window


It looks like you need an additional variable to indicate when a search is performed, and then render the view including the grid.  You are only passing in the Employees list into the view.  I would think that you need to create a super class that has the state variable and the employees list.

public class EmployeeModel
{
     public List<Employee> EmployeeList { get; set; }
     public bool IsSearch { get; set; }
}

Open in new window

0
nicemanishAuthor Commented:
Its look like that I have to find answer from myself.once u will get it post to people how to do it.
0
Bob LearnedCommented:
"Its look like that I have to find answer from myself"

Open in new window

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.
0
nicemanishAuthor Commented:
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
0
nicemanishAuthor Commented:
craete a second action result with parameter ,and take the action as post.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nicemanishAuthor Commented:
done
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.