0

Actionlinkでテーブルを作成しました。Actionlink が新しいビューを開き、Action のパラメータとして @item - 完全なオブジェクトを送信したい。どうすれば作れますか?

モデル:

public class MyClass
    {
        //I have properties here.
    }

コントローラ:

public class MyController : Controller
{
    public ActionResult ActionName(MyClass tm)
        {
            //have a breakpoint here
            return View();
        }
}

意見:

<table>
    <tr>
        <th> Column title one </th>
        <th> Column title two </th>
        <th> Column title three </th>
    </tr>

@foreach (var item in @Model)
    {
        <tr>
            <td> @item.PropertyOne </td>
            <td> @item.PropertyTwo </td>
            <td> @item.PropertyThree </td>

            @if (ViewData["smth"] == "true")
                {
                    <td> @Html.ActionLink("Edit", "ActionName", "My", new { tm = @item }, null) </td>
                }
        </tr>  
    }
</table>

私は、MyClass tm で ActionLink をクリックした後にのみ、すべてが正常に機能することを言う必要があります。@アイテムではありません。「param1 = @item.propertyOne、param2 = @item.propertyTwo」などを書きたくない場合、どのようにアクションに送信できますか?

ありがとうございました。

4

1 に答える 1

1

ハイパーリンク (ActionLink) を使用することは実際には不可能です。追加のルート値として入力したものは、ほとんど (エリアを除く) クエリ文字列のキーと値のペアに変換されます。ただし、多くのオプションがあります。

アイテムはモデルの一部であり、アクション メソッドで構築されるため、次のことが可能です。

  • 別のアクション メソッドで使用するために、アクション メソッド内のアイテムのリストを (おそらくMemoryCacheTempDataまたはRedisなどを介して) キャッシュします。

  • アイテムのリストをセッションに保存します。

  • 同じ取得方法 (つまり、同じサービス コール) を使用して、別のアクション メソッドで同じアイテムを取得します。

于 2013-09-04T11:48:35.523 に答える