0

我正在尝试在主索引视图中放置一个搜索栏,以便我可以搜索特定的客户。我会搜索一个名字,它工作正常,但如果我再次尝试搜索,我会得到..

“/”应用程序中的服务器错误。无法找到该资源。

说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。

请求的 URL:/Client/Client/Index

我希望能够重复搜索并返回主索引。

控制器类

public class ClientController : Controller
{
    private VolumeV2Context db = new VolumeV2Context();

    //
    // GET: /Client/

    public ActionResult Index(string SearchParam)
    {
        if (SearchParam == null)
        {
              //just load the main index 
            return View(db.Clients.Take(25).ToList());
        }
        else
        {
             //search for the client name
            var clients = db.Clients.Where(c => c.FirstName.Contains(SearchParam) || c.LastName.Contains(SearchParam)).Take(10).ToList();
            return View(clients);

        }
    }

索引视图 我在这里也为每个客户逐行使用局部视图。我以为这会让我更容易

@model IEnumerable<VolumeV2.Models.Clients>


@{  
ViewBag.Title = "Index";

}

<h2>Index</h2>

<form action="Client/Index" method="get" >
<input type="text" name="SearchParam" />
<input type="submit" value="Search" />
<table class="client" id ="results">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.FirstName)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.LastName)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.PhoneNumber)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Email)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.EmailList)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.HairType)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Description)
    </th>
    <th></th>
</tr>


   @foreach( var item in Model){

 @Html.Partial("SearchedClients",item)

}
           </table>
</form>

局部视图

@model VolumeV2.Models.Clients


<tr >
    <td>
        @Html.DisplayFor(model => model.FirstName)
    </td>
    <td>
        @Html.DisplayFor(model => model.LastName)
    </td>
    <td>
        @Html.DisplayFor(model => model.PhoneNumber)
    </td>
    <td>
        @Html.DisplayFor(model => model.Email)
    </td>
    <td>
        @Html.DisplayFor(model => model.EmailList)
    </td>
    <td>
        @Html.DisplayFor(model => model.HairType)
    </td>
    <td>
        @Html.DisplayFor(model => model.Description)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
        @Html.ActionLink("Details", "Details", new { id = Model.Id }) |
        @Html.ActionLink("Delete", "Delete", new { id = Model.Id }) |
        @Html.ActionLink("Address", "GetAddress", new { id = Model.Id })

    </td>
</tr>
4

1 回答 1

0

将表单操作从“/Client/Index”更改为“../Client/Index”

于 2013-03-05T04:02:37.813 回答