c# - 有没有办法使用 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>
该模型在该字典中返回一个空值元组。
解决方案
根据 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"/>
通过将名称更改为类值属性并将值更改为单个值,然后添加隐藏输入作为它正确发布的另一个值,并且模型是完整的字典值和所有。
推荐阅读
- amazon-web-services - 无法将 lambda 与 cloudwatch 事件触发器链接
- r - 如何在不使用重复()或唯一()的情况下识别列中存在一次的观察?
- javascript - 如何在Js中访问手机前置摄像头并录制视频?
- javascript - 动态更改图片 360
- python - Python中如何正确调用其他目录中定义的函数?
- java - 了解 Java 中的类型擦除
- oracle - 我如何从这个 ERD 实现到这个 EERD?(在甲骨文中)
- powerbi - Power BI - 如何计算值相对于单独列出现的次数?
- c# - 检查数字是否为 32 位无符号且没有警告?
- flutter - 如何在 Flutter 中隐藏 android 导航栏(返回/主页/菜单)