1

ドロップダウンリストとページネーションシステムを備えたビューがあります。ページネーション リンクの 1 つをクリックしたときに、ドロップダウン リストの選択したインデックス値を保持する必要があります。

これはドロップダウンリストです:

@Html.DropDownList("typeId", types, "-- Filter by type --", new { style= "width: 110px;", onchange = "location.href='" + Url.Action("List", new { month = selectedMonth, year = selectedYear }) + "?typeId=' + $(this).val()" })

そしてページネーションシステム:

<div style="margin-top: 15px">

    <span>
        @Html.ActionLink("First", "List", new { month = months[0].Item1, year = months[0].Item3 })
    </span>
    <span style="margin-right: 15px">
        @Html.ActionLink("Previous", "List", new { month = previousMonth, year = previousMonthYear })
    </span>
    @foreach (var entry in months)
    {
        if (selectedMonth == entry.Item1 && selectedYear == entry.Item3)
        { 
        <span>
            @Html.ActionLink(entry.Item2, "List", new { month = entry.Item1, year = entry.Item3 }, new { @class = "current" })
        </span>
        }
        else
        {
        <span>
            @Html.ActionLink(entry.Item2, "List", new { month = entry.Item1, year = entry.Item3 })
        </span>
        }
    }
    <span style="margin-left: 15px">
        @Html.ActionLink("Next", "List", new { month = nextMonth, year = nextMonthYear })
    </span>
    <span>
        @Html.ActionLink("Last", "List", new { month = months[11].Item1, year = months[11].Item3 })
    </span>
</div>

どんなアイデアでも大歓迎です。

PD: ページネーション リンクのクリック時に、選択した値をルート値として渡したい。

私はこれをやろうとしました:

@Html.ActionLink("Last", "List", new { month = months[11].Item1, year = months[11].Item3, typeId = "$('#typeId option:selected')" })

しかし、潜在的に危険な Request.Path 値がクライアントから検出されました (:) エラーが発生します。このエラーを防ぐにはどうすればよいですか?

4

3 に答える 3

0

回避策を見つけました(同僚の助けを借りて):昔ながらのhtmlリンクで、次のようにURLを設定しました:

<a href="@(Url.Action("List", "Notifications", new { month = months[0].Item1, year = months[0].Item3 }) + (typeId.HasValue ? "/" + typeId.Value : ""))">First</a>
于 2013-08-07T14:18:17.067 に答える
0

ポストバック ドロップダウンがある場合、MVC であるため ViewState を使用できないため、値が失われます。したがって、私が提案するのは次のいずれかです。

  1. このドロップダウンを Form タグから取り出します
  2. 値をコントローラーに入れ、Viewstate に戻します。
  3. ビューの部分レンダリングを行う

現在の構造に関して役立つかどうかはわかりません。

于 2013-08-07T12:08:44.127 に答える