没有与编辑器模板绑定的模型

时间:2014-12-26 16:20:16

标签: asp.net-mvc devexpress mvc-editor-templates

我有以下观点:

@model StockItemDetailModel

@using (Html.BeginForm("EditDetails", "StockItem"))
{
    <div class="ItemDetails">
        <table class="datagrid">
            <tr>
                <th colspan="3">@Model.StockItemPropertiesCaption</th>
            </tr>
            <tr>
                <td class="label">@Model.StoreLabel</td>
                <td class="value">@Html.DisplayFor(item => item.Store)</td>
                <td></td>
            </tr>
            <tr>
                <td class="label">@Model.BuildingLabel</td>
                <td class="value">@Html.DevExpress().TextBoxFor(model => model.Building).GetHtml()</td>
                <td class="validationError">@Html.ValidationMessageFor(model => model.Building)</td>
            </tr>

...

             <tr>
                <td colspan="3">@Html.EditorFor(model => model.AmountModel, "Amounts")</td>
>            </tr>
            <tr>
                <td colspan="3" class="validationError">@Html.ValidationMessageFor(model => model.AmountModel)</td>
            </tr>
            <tr />
        </table>
    </div>
    <br />

    <input type="submit" class="button" value="@Model.SaveButtonLabel" />
}

部分视图“金额”如下:

@model AmountModel

    <table>
    <tr>
        <td class="label">@Model.AmountLabel</td>
        <td class="value">
            @Html.DevExpress().SpinEditFor(model => model.DenormalizedNetAmount,
                    settings =>
                    {
                        settings.Name = "DenormalizedNetAmount";
                        settings.Width = 153;
                        settings.Properties.DisplayFormatString = @"0.0,0";
                        settings.Number = 0;
                    }).GetHtml()
        </td>
        <td class="value">
            @Html.DevExpress().ComboBoxFor(model => model.NetAmountUnit,
                    settings =>
                    {
                        settings.Name = "NetAmountUnit";
                        settings.Width = 60;
                    }).BindList(args => this.Model.AllUnits, args => this.Model.AllUnits).GetHtml()
        </td>
    </tr>

...

    </table>

这是AmountModel:

        public class AmountModel
        {
            public decimal DenormalizedNetAmount { get; set; }
            public string NetAmountUnit { get; set; }

...

            public string AmountLabel
            {
                get { return i18n.StockItemDetailModel_AmountLabel; }
            }

...
        }

但是输入字段的值不在模型绑定器创建的Controller中的模型中。 为什么模型绑定器无法识别编辑器模板中的值?

当我传递FormCollection时,在名称“AmountModel。〜”下正确传递的值

public ActionResult EditDetails(FormCollection collection)
{
var netamount = collection["AmountModel.DenormalizedNetAmount"]; //correct value!

...

}

1 个答案:

答案 0 :(得分:0)

使用强类型(*** For)帮助程序时, NOT 指定名称属性。

请参阅DevExpress论坛上的MVC Data Editors - Model Binding and Editing学习资源。