0

特定のクライアントを検索できるように、メインのインデックス ビューに検索バーを配置しようとしています。名前を 1 回検索すると問題なく動作しますが、もう一度検索しようとすると、..

「/」アプリケーションでサーバー エラーが発生しました。リソースが見つかりません。

説明: HTTP 404。探しているリソース (またはその依存関係の 1 つ) は、削除されたか、名前が変更されたか、一時的に利用できない可能性があります。次の 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);

        }
    }

インデックス ビュー ここでも、クライアントごとに 1 行ずつ部分ビューを使用します。私はそれが私にとってそれをより簡単にするだろうと思った

@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 に答える