从单个单选按钮的选择中显示一组/选择单选按钮的最佳方法? [英] Best way to display a group/selection of radiobuttons from the choice of a single radiobutton?

查看:160
本文介绍了从单个单选按钮的选择中显示一组/选择单选按钮的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,对于某些问题,它会询问是否包含某些内容以及是否不提供原因.

I have a form which for some questions would ask if something was included and if it isn't to supply a reason.

因此,我需要一个单选按钮,将其值记录到数据库中,该值与我用RadioButtonFor设置的正常值相同,如果选择了否"(false),则将显示其他单选按钮的组/列表.

So I need a radio button which records to the database it's value like normal which I have setup with a RadioButtonFor and if "No"(false) is selected then a group/list of other radiobuttons will display.

如果这方法不可行,这只是理想的解决方案,那么另一种解决方案可能是在控制器中使用if语句,以便如果该主单选按钮的值为"Yes"(true),那么它将设置将表单记录到数据库时,x,y和z单选按钮的值设置为否"(false).

Ofc this is just the ideal solution if this method isn't feasible then another solution would be to maybe a if statement in the controller so that if that main radiobutton has a value of "Yes"(true) then it would set the values of x, y and z radiobuttons to "No"(false) when it records the form to the database.

这些是我对如何获得相同最终结果的两个想法,但对于第一个想法,我认为执行其功能的最简单方法是在jquery中,我对此相当陌生,因此很难提出怎么做

These are the 2 ideas I have on how to get the same end result but for the 1st idea I think the easiest way to perform it's function would be in jquery which I'm fairly new at so would struggle to come up with how to do it

对于第二个想法,它不是1理想,而2是我不确定如何引用那些单选按钮/对if语句进行编码以完成所述任务.

For the 2nd idea it's 1 not ideal and 2 I'm not sure how I would then reference those radiobuttons/code the if statement to do said task.

任何其他想法也将受到欢迎,但希望能对如何实现这些想法有所帮助.

Any other ideas would also be welcome but hopefully with help on how to implement them.

推荐答案

好吧,我想出了最简单的方法来使控制器对验证进行排序. if (wd.AppTher == true) { wd.AppTherRea = 0; }这是一个下拉列表的示例,对于另一个单选按钮,它将是"0"而不是您想要的下拉列表为"false"的任何值,或者您想要/具有int的多个选项db字段类型,那么您只需将N/A或w/e值也设置为=,对于多个RB或DDL,然后在{和}之间添加更多,wd是为代表表而指定的值,否则为viewmodel值可以使用.

Well I figured out the simpliest way to get the controller to sort out the validation which was if (wd.AppTher == true) { wd.AppTherRea = 0; } this is the example for a drop down and for another radiobutton it would be instead of "0" or whatever value u want for the drop down for it to be "false" or if you want/have multiple options with int at the db field type then you just set your N/A or w/e value as the = too, for multiple RB or DDL then just add more in between { and }, wd was the value assigned to represent the table and otherwise a viewmodel value could be used.

这篇关于从单个单选按钮的选择中显示一组/选择单选按钮的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆