Hi aspnoob,
I have created sample that full-fill your requirement.
Here I am making use of Microsoft’s Northwind Database. You can download it from here.
Controller
public ActionResult Index(int no = 10)
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem() { Text = "1", Value = "1" });
items.Add(new SelectListItem() { Text = "2", Value = "2" });
items.Add(new SelectListItem() { Text = "3", Value = "3" });
items.Add(new SelectListItem() { Text = "4", Value = "4" });
items.Add(new SelectListItem() { Text = "5", Value = "5" });
items.Add(new SelectListItem() { Text = "6", Value = "6" });
items.Add(new SelectListItem() { Text = "7", Value = "7" });
items.Add(new SelectListItem() { Text = "8", Value = "8" });
items.Add(new SelectListItem() { Text = "9", Value = "9" });
items.Add(new SelectListItem() { Text = "10", Value = "10" });
var ddl = from n in items
select n.Text;
ViewBag.No = ddl;
NorthwindEntities entities = new NorthwindEntities();
var products = (from e in entities.Products
select e).Take(no);
return View(products);
}
CSHTML
@model IEnumerable<DropDownListFilterRecords.Product>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
table {
border: 1px solid #ccc;
}
table th {
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td {
padding: 5px;
border-color: #ccc;
}
</style>
</head>
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
@Html.DropDownList("No", new SelectList(ViewBag.No))
<input type="submit" value="Filter" />
}
<br />
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.QuantityPerUnit)
</th>
<th>
@Html.DisplayNameFor(model => model.UnitPrice)
</th>
<th>
@Html.DisplayNameFor(model => model.UnitsInStock)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.QuantityPerUnit)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitPrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitsInStock)
</td>
</tr>
}
</table>
</body>
</html>
Screenshot