将数据从@ Html.DisplayFor传递到Controller时为空值

时间:2015-02-12 17:08:12

标签: c# asp.net-mvc razor

我需要将ViewModel在Razor View页面上显示的数据传递给Controller。用户在@Html.EditorFor中输入的值正在成功传递,但来自@ Html.DisplayFor for的数据不是。我错过了什么?

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <table>
        <tr>
            <td style="text-align: center; vertical-align: middle;">
                <div class="main-container">
                    <h3 class="main-title" id="bold-title">
                        @Html.DisplayFor(model => model.EmailReceiver)
                    </h3>
                    <h3 class="main-title" id="thin-title">
                        @Html.DisplayFor(model => model.PurchaseDesc)
                    </h3>
                    @Html.EditorFor(model => model.EmailSender, new { htmlAttributes = new { @placeholder = "Your e-mail", @id = "e-mail" } })
                    @Html.EditorFor(model => model.CardNumber, new { htmlAttributes = new { @placeholder = "Your card number", @id = "card" } })
                    @Html.EditorFor(model => model.CardValidDate, new { htmlAttributes = new { @placeholder = "MM / YYYY", @id = "date" } })
                    @Html.EditorFor(model => model.CVV, new { htmlAttributes = new { @placeholder = "CVV", @id = "cvv" } })
                    <button class="button" id="pay-button" type="submit">
                        <div id="price">Pay @Html.DisplayFor(model => model.TotalAmount)$</div>
                        <br>
                        <div id="ok">Complete!</div>
                    </button>
                </div>
            </td>
        </tr>
    </table>
}

1 个答案:

答案 0 :(得分:0)

您需要添加隐藏字段才能获取传回的只读值。使用@Html.HiddenFor生成等效的隐藏字段。