2

inputタイプの自動的に生成されたボックスを含むビューがありますtext。[Email Results] ボタンをクリックすると、コードによって CalculatedResults コントローラー内の EmailResults アクションに移動します。ここまでは順調ですね。しかし、EmailResults アクションのパラメーターとして FormCollection を使用しているにもかかわらず、null として送信されており、その理由がわかりません。フォームからテキストボックスをキャプチャできるようにする必要があります-助けてください!!. 以下の View コードでは、生成されたテキスト ボックスが半分過ぎたところにあります。

マイ ビュー コード

@using (Html.BeginForm("EmailResults", "CalculatedResults", FormMethod.Post, new { data_ajax = "false" }))
        {
            <table>
                <thead>
                    <tr>
                        <td>Ingredient</td>
                        <td>Qty (gm)</td>
                    </tr>
                </thead>
                @foreach (var i in Model)
                {
                    if (Convert.ToDecimal(i.Qty) < 0)
                    {
                        <tr>
                            <td style="border: 1px solid red; color: red;">@i.Ingredient</td>
                            <td style="border: 1px solid red; color: red;">@i.Qty</td>
                        </tr>
                    }

                    else if (Convert.ToDecimal(i.Qty) == 0m)
                    {
                        continue;
                    }

                    else
                    {
                        if (i.Ingredient.Contains("Active"))
                        {
                        <tr>
                            <td>@i.Ingredient<br />
                                <input type="text" name="actives" /></td>
                            <td>@i.Qty</td>
                        </tr>
                        }
                        else
                        {
                        <tr>
                            <td>@i.Ingredient</td>
                            <td>@i.Qty</td>
                        </tr>
                        }
                    }
                }

            </table>
        }
        <div style="float: left">
            @Html.ActionLink("Email Results", "EmailResults", "CalculatedResults", new { crpk = @ViewBag.crpk }, new { data_icon = "arrow-r", data_role = "button" })
        </div>

私のコントローラーコード

public ViewResult EmailResults(int crpk, FormCollection collection)
{
    CapWorxQuikCapContext context = new CapWorxQuikCapContext();

    //List<string> variables = new List<string>();
    //foreach (var item in Request.Form)
    //{
    //    variables.Add(item.ToString());
    //}

    CalculatedResults cr = (from i in context.CalculatedResults where i.Pk == crpk select i).SingleOrDefault();
    Helpers.Email.EmailResults(cr);

    return View();
}

スクリーンショットは次のとおりです。

ここに画像の説明を入力

4

1 に答える 1

4

formCollection は、フォームをコントローラーに送信したときにのみ表示されます。また

  1. 使用する<input type="submit" value="Email Results" />
  2. フォームを送信するために作成した ActionLink に jquery ハンドラを接続します。
于 2013-04-12T03:24:19.377 に答える