c# - 如何使用文本框值在单选按钮上设置值
问题描述
我的模型中有一个属性,它定义了用户要插入的数量。
为此,我使用 3 个单选按钮,如下所示:
我用于此的代码如下:
<div>
@Html.RadioButtonFor(m => m.LabelsQuantity, "100", new { @class = "custom-control-inline radiobtn" }) @Html.Label("100", new { @class = "custom-label-inline " })
</div>
<div>
@Html.RadioButtonFor(m => m.LabelsQuantity, "1000", new { @class = "custom-control-inline radiobtn" }) @Html.Label("1000", new { @class = "custom-label-inline " })
</div>
<div>
@Html.RadioButtonFor(m => m.LabelsQuantity, "Other" , new { @class = "custom-control-inline radiobtn" }) @Html.Label("Others", new { @class = "custom-label-inline " })
</div>
<div>
@Html.TextBoxFor(m => m.LabelsQuantity, string.Empty, new { @class = "custom-control-inline form-control enable_tb", type = "number", disabled = "true" })
</div>
问题是我在文本框中插入的值没有被传递给控制器,只有另一个字符串。
我需要能够覆盖视图中的值或能够在控制器的文本框中获取值。
有什么帮助吗?谢谢你。
解决方案
您需要为将为其Others
发布值的文本框引入另一个属性:
<div>
@Html.RadioButtonFor(m => m.LabelsQuantity, "100", new { @class = "custom-control-inline radiobtn" }) @Html.Label("100", new { @class = "custom-label-inline " })
</div>
<div>
@Html.RadioButtonFor(m => m.LabelsQuantity, "1000", new { @class = "custom-control-inline radiobtn" }) @Html.Label("1000", new { @class = "custom-label-inline " })
</div>
<div>
@Html.RadioButtonFor(m => m.LabelsQuantity, "Other" , new { @class = "custom-control-inline radiobtn" }) @Html.Label("Others", new { @class = "custom-label-inline " })
</div>
<div>
@Html.TextBoxFor(m => m.Others, string.Empty, new { @class = "custom-control-inline form-control enable_tb", type = "number", disabled = "true" })
</div>
在模型中:
public class ViewModel
{
public string LabelsQuantity { get; set; }
...............
...............
public string Others { get; set; }
}
现在在控制器中,您需要检查是否选择了其他单选按钮,使用文本框中提供的选定值。
推荐阅读
- python-3.x - 如何在我的 AboutDialogInfo 上删除 About 一词
- forms - 为什么 Form 中的 validate() 会跳过一些验证器(Flutter)?
- mysql - Mysql 查询到正确的 Laravel $query
- amazon-web-services - 如何修复 AWS s3 boto3 中的“调用 GetObject 操作时出现 AuthorizationHeaderMalformed”错误
- c# - 如何插入数据库 SQL 事务?
- ruby-on-rails - 在 Rails 上做出反应 ReactOnRails::PrerenderError
- flutter - 如何将流与提供者混合?
- android - Android 的活动视图
- sublimetext3 - Sublime Text:添加“Permute Lines -> Shuffle”快捷键
- c - structure initialization failed