below is the code for the filtered data of dropdownlist with the textbox i.e. data of dropdownlist is bind with the textbox and what i need to do is i want to show the filtered data on the next page on click of the submit button. please give me solution for this.
CONTROLLER------------SEARCHRESULTCONTROLLER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SearchingInMVC4.Models;
namespace SearchingInMVC4.Controllers
{
public class SearchResultController : Controller
{
//
// GET: /SearchResult/
private EmployeeDataContext objEmpDataCont;
public SearchResultController()
{
objEmpDataCont = new EmployeeDataContext();
}
public ActionResult Index(string Search_Data, string Emp_Dept)
{
var DeptList = new List<string>();
var DeptQuery = from q in objEmpDataCont.Employees orderby q.Dept select q.Dept;
DeptList.AddRange(DeptQuery.Distinct());
ViewBag.Emp_Dept = new SelectList(DeptList);
IList<employeemodel> empList = new List<employeemodel>();
var emp = from q in objEmpDataCont.Employees
select q;
if (!String.IsNullOrEmpty(Search_Data))
{
emp = emp.Where(s => s.Name.Contains(Search_Data));
}
if (!String.IsNullOrEmpty(Emp_Dept))
{
emp = emp.Where(s => s.Dept==Emp_Dept);
}
var myEmpList = emp.ToList();
foreach (var empData in myEmpList)
{
empList.Add(new EmployeeModel()
{
ID = empData.ID,
Emp_ID = empData.Emp_ID,
Name = empData.Name,
Dept = empData.Dept,
City = empData.City,
State = empData.State,
Country = empData.Country,
Mobile = empData.Mobile
});
}
return View(empList);
}
}
}
VIEW---- INDEX.CSHTML
@model IEnumerable<searchinginmvc4.models.employeemodel>
@{
ViewBag.Title = "A MVC 4 Search Application With TextBox & DropDown Option";
}
@using (Html.BeginForm("Index", "SearchResult", FormMethod.Get))
{}
@foreach (var item in Model) {
}
@Html.DisplayNameFor(model => model.Emp_ID)
| @Html.DisplayNameFor(model => model.Name)
| @Html.DisplayNameFor(model => model.Dept)
| @Html.DisplayNameFor(model => model.City)
| @Html.DisplayNameFor(model => model.State)
| @Html.DisplayNameFor(model => model.Country)
| @Html.DisplayNameFor(model => model.Mobile)
| |
@Html.DisplayFor(modelItem => item.Emp_ID)
| @Html.DisplayFor(modelItem => item.Name)
| @Html.DisplayFor(modelItem => item.Dept)
| @Html.DisplayFor(modelItem => item.City)
| @Html.DisplayFor(modelItem => item.State)
| @Html.DisplayFor(modelItem => item.Country)
| @Html.DisplayFor(modelItem => item.Mobile)
| |
MODEL---EMPLOYEEMODEL.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace SearchingInMVC4.Models
{
public class EmployeeModel
{
public int ID { get; set; }
public string Emp_ID { get; set; }
public string Name { get; set; }
public string Dept { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
public string Mobile { get; set; }
}
}