首页 > 解决方案 > 有没有办法使用 mvc 发布一个元组值?

问题描述

我正在尝试使用 razer 视图和 mvc 作为元组发布两个值。

我尝试了所有不同的格式,用逗号分隔值,把括号和括号放在尖括号中。

<div class="location-input">
   <input id="ElectionJsonObject.LocationPerVotingTypeDictionary[@item.Key] [@i]" type="checkbox" name="ElectionJsonObject.LocationPerVotingTypeDictionary[@item.Key][@item.Value.ElementAt(i).Key]" value="<(@item.Value.ElementAt(i).Value.Item1.ToString(), @item.Value.ElementAt(i).Value.Item2>" checked />
   <input type="hidden" name="ElectionJsonObject.LocationPerVotingTypeDictionary[@item.Key][@item.Value.ElementAt(i).Key]" value="False" />
   @Model.ElectionJsonObject.LocationPerVotingTypeDictionary[@item.Key].ElementAt(i).Key - @item.Value.ElementAt(i).Value.Item2
</div> 

该模型在该字典中返回一个空值元组。

标签: c#asp.net-mvc

解决方案


根据 Matheus Lemos 的评论,我改用了一个类。

            public class LocationInformation
            {
                public string LocationDetails { get; set; }
                public bool Display { get; set; }

                //For data transfer
                public LocationInformation()
                {

                } 

这是课堂。

 <input id="ElectionJsonObject.LocationPerBallotTypeDictionary[@ballotType][@locationId]" type="checkbox" name="ElectionJsonObject.LocationPerBallotTypeDictionary[@ballotType][@locationId].Display" value="@locationInfo.Display.ToString()" checked />



 <input type="hidden" name="ElectionJsonObject.LocationPerBallotTypeDictionary[@ballotType][@locationId].LocationDetails" value="@locationInfo.LocationDetails"/>

通过将名称更改为类值属性并将值更改为单个值,然后添加隐藏输入作为它正确发布的另一个值,并且模型是完整的字典值和所有。


推荐阅读