Hi mukesh1,
Check the below example.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
NorthwindEntities db = new NorthwindEntities();
public ActionResult FindSearch(int partner, string minimum_age, string maximum_age, int relegion)
{
List<Employee> userlist = db.Employees.Where(s => s.Country == minimum_age && s.City == maximum_age).ToList();
return PartialView("_EmployeeDetails", userlist);
}
}
Index View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
</head>
<body>
<div align="center">
@Html.DropDownList("Minimum_Age", new List<SelectListItem>()
{
new SelectListItem(){ Text= "USA", Value = "USA"},
new SelectListItem(){ Text= "UK", Value = "UK" }
}, new { @class = "form-control" })
@Html.DropDownList("Maximum_Age", new List<SelectListItem>()
{
new SelectListItem(){ Text= "Seattle", Value = "Seattle"},
new SelectListItem(){ Text= "Tacoma", Value = "Tacoma" },
new SelectListItem(){ Text= "Kirkland", Value = "Kirkland" },
new SelectListItem(){ Text= "Redmond", Value = "Redmond"},
new SelectListItem(){ Text= "London", Value = "London"}
}, new { @class = "form-control" })
<br />
<br />
<div id="dvPartialView" class="divpartial"></div>
<input type="submit" value="Details" id="btnDetails" class="btn btn-primary" onclick="javascript:Callpartialview()" />
</div>
<script type="text/javascript">
function Callpartialview() {
var Minimum_Age = document.getElementById("Minimum_Age").value;
var Maximum_Age = document.getElementById("Maximum_Age").value;
var Partner = 1;
var Relegion = 1;
$.ajax({
url: '@Url.Action("FindSearch", "Home")',
dataType: "html",
data: { "partner": Partner, "minimum_age": Minimum_Age, "maximum_age": Maximum_Age, "relegion": Relegion },
type: "GET",
contentType: "application/json",
success: function (response) {
$('.divpartial').html(response);
},
error: function (err) {
alert(err.responseText);
}
});
}
</script>
</body>
</html>
EmployeeDetails Partial View
@model IEnumerable<_160787_WebGrid_PartialView.Employee>
@{
WebGrid grid = new WebGrid(Model, canPage: true);
}
@if (Model.Count() > 0)
{
@grid.GetHtml(tableStyle: "table-design table table-bordered table-hover dataTable", fillEmptyRows: false,
columns: new[]
{
grid.Column(columnName:"FirstName", header:"Name"),
grid.Column(columnName:"EmployeeID", header:"Id"),
grid.Column(columnName:"Country", header:"Country")
})
}
Screenshot