繁体   English   中英

Dictionary <,>绑定到Asp.Net MVC中的控制器

[英]Dictionary<,> Binding to a Controller in Asp.Net MVC

我有一个如下的课程。

   public class ProductViewGridModel
    {
        public long Id { get; set; }
        public string PackageCode { get; set; }
        public string ProductName { get; set; }
        public string ProductCategory { get; set; }
        public IDictionary<string, string> Localizations { get; set; }

    }

我在模型中渲染了这样的视图(foreach语句运行到表中,此处未显示)。

 @foreach (var localization in Model.Localizations)
                {
                    var p = localization.Value;
                    <tr>
                        <td class="adminData">
                            <input class="k-textbox" type="text" value="@p" name="productView.Localizations[@localization.Key]" />
                            <input type="hidden" value="@p" name="productView.Localizations[@localization.Key]" />
                        </td>
                    </tr>
                }

我有一个按钮,该按钮通过ajax调用将表单值发送到控制器。

其他模型绑定也可以,但是我想将所有本地化输入绑定到本地化模型。 但是本地化始终为空。 我该如何绑定呢?

输入名称错误。 默认的modelbinder将查找属性Localizations

@foreach (var localization in Model.Localizations)
{
    var p = localization.Value;
    <tr>
        <td class="adminData">
            <input class="k-textbox" type="text" value="@p" name="Localizations[@localization.Key]" />
            <input type="hidden" value="@p" name="Localizations[@localization.Key]" />
        </td>
    </tr>
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM