I
@model IEnumerable<search15622.Models.Employee>
@{
ViewBag.Title = "Index";
}
<div style="font-family:Arial">
<h2>Index</h2>
<p>
@using (Html.BeginForm("Index", "Search", FormMethod.Get))
{
<b> Search by</b> @Html.RadioButton("searchby", "Name", true)<b> Name</b>
@Html.RadioButton("searchby", "Gender") <b> Gender</b><br />
@Html.TextBox("search") <input type="submit" value=" Search" />
}
</p>
<table border="1" ">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().Name)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Gender)
</th>
<th>
@Html.DisplayNameFor(model => model.First().EmailId)
</th>
<th>
@Html.DisplayNameFor(model => model.First().City)
</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th> Action</th>
</tr>
@if (Model.Count() == 0)
{
<tr>
<td colspan="5">
No record found
</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.EmailId)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</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>
Search Controller
using search15622.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
namespace search15622.Controllers
{
public class SearchController : Controller
{
// GET: search
SearchMvc15622Entities db = new SearchMvc15622Entities();
// GET: Employee
public ActionResult Index(string Searchby, string search, int? page)
{
if (Searchby == "Gender")
{
var model = db.Employees.Where(emp => emp.Gender == search || search == null).ToList().ToPagedList(page ?? 1, 3);
return View(model);
}
else
{
var model = db.Employees.Where(emp => emp.Name.StartsWith(search) || search == null).ToList().ToPagedList(page ?? 1, 3);
return View(model);
}
}
}
}
Comments
Post a Comment