有没有一种方法可以使用MVC发布元组值?

时间:2019-05-14 18:57:51

标签: c# asp.net-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> 

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

1 个答案:

答案 0 :(得分:1)

根据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"/>

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

相关问题