1

我正在尝试在控制器的索引中进行搜索,以在同一视图(索引)中检索搜索结果,因为这是操作:

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 的情况下这样做吗?谢谢,

4

1 回答 1

2

在调用输入时传入SeatchParam控制器SearchParam

所以改变

public ActionResult Index(string SearchParam)
于 2012-11-17T19:51:01.927 回答