0

フォーム送信時にモデル データ全体をインデックス ポストに返そうとしています。URLパラメータで渡されたIDのみを返しています。なんで?

ここに画像の説明を入力

@using Volunteer.BootstrapSupport
@model IEnumerable<Volunteer.Models.Activity>
 @using (Html.BeginForm())
{
    <h2>Member Volunteering List </h2>
    <div>
            <button type="submit" class="btn btn-primary" >New Activity</button>
    </div>
    <table id="volunteerlist" class="table table-striped table-bordered table-hover .table-condensed">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Committee.Name)
                </th>

                <th>
                    @Html.DisplayNameFor(model => model.Committee.Type)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Role)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.EndDate)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Source)
                </th>
                <th></th>
            </tr>
4

2 に答える 2

0

プロパティの表示に加えて、隠しフィールドも含める必要があります。

@Html.HiddenFor(m => m.Role)

入力要素を作成していないプロパティごとにこれを行います

于 2013-03-22T14:16:01.727 に答える
0

モデル プロパティをインデックスに返したい場合は、プロパティをルート値として追加する必要があります。

return RedirectToAction("検索", new{"キー", 値});

非表示のフィールドは、送信時に渡すデータを格納する 1 つの方法です。ルーティングを使用するのはより複雑ですが、Role url としてより適切なソリューションです。いくつかの非表示の値については問題なく動作しますが、多数のルート値を持つ多くのアクション リンクを作成する必要がある場合は、Routing を調べてください。

于 2013-03-22T19:24:48.553 に答える