我尝试在一个控制器的索引中进行搜索,以在相同的视图( index )中检索搜索结果,因此操作如下:
public ActionResult Index(string SeatchParam)
{
 var Employees = db.Employees.Include(e => e.Location).Include(e =>          e.Department).Where(e => e.FirstName.Contains(SeatchParam)|| e.FatherName.Contains(SeatchParam) || e.LastName.Contains(SeatchParam) || e.Location.LocationName.Contains(SeatchParam) || e.Department.DepartmentName.Contains(SeatchParam)).Take(10);
        return View(Employees.ToList());
    }视图是这样的:
@model IEnumerable<OG.Models.Employee>
@{
ViewBag.Title = "Index";
}
<h2>Search Employees</h2>
<form action="Employee/Index"  method="get">
<input type="text" name="SearchParam" />
<input type="submit" value="Search" />
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table border="10">
<tr>
   <th>
        @Html.DisplayNameFor(model => model.EmployeeId)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.FullName)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Department.DepartmentName)
    </th>
     <th>
        @Html.DisplayNameFor(model => model.Location.LocationName)
    </th>
    <th></th>
</tr>
@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.EmployeeId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.FullName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Department.DepartmentName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Location.LocationName)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.EmployeeId  }) |
        @Html.ActionLink("Details", "Details", new { id = item.EmployeeId }) |
        @Html.ActionLink("Delete", "Delete", new { id = item.EmployeeId })
    </td>
</tr>
}
</table>
</form>当我搜索时,我没有找到任何结果,没有AJAX或Json我能做到吗?谢谢,
发布于 2012-11-18 03:51:02
当您的输入称为SearchParam时,将SeatchParam传递给控制器
所以改变吧
public ActionResult Index(string SearchParam)https://stackoverflow.com/questions/13433488
复制相似问题