【问题标题】:How can I change a DropDownList to Radio Button list?如何将 DropDownList 更改为单选按钮列表?
【发布时间】:2015-07-29 10:52:17
【问题描述】:

寻求 ASP 编码方面的帮助.... 我不知道 ASP,但不知何故需要跟进当前的项目,希望有人可以帮助我....

我有一个带有下拉列表的表单,客户想将其更改为单选按钮。我发现在 .cshtml 文件中有如下代码应该很有用:

@Html.DropDownListFor(m => m.selectedBSFlag, Model.bsFlag, new { @class =  "form-control input-sm", ng_model = "inputForm.bsFlag" })

任何想法如何进行更改?如果需要更多信息,请告诉我。谢谢。

最好的问候, 天空

【问题讨论】:

  • 为了给出一个好的答案,您需要展示您的模型 - 您要将所选值绑定到的属性是什么,包含显示可供选择的选项的集合的属性是什么,以及该集合中模型的属性是什么?

标签: asp.net asp.net-mvc


【解决方案1】:

我们不会称它为 ASP,我们会称它为 ASP.NET MVC。

您应该检查RadioButtonFor HTML 扩展。 This question 提供了一个很好的例子。

复制,便于阅读

    public class PropMgmtViewModel
{
    public Property Property { get; set; }
    public IEnumerable<Property> Properties { get; set; }
    public SelectList Cities { get; private set; }


    static Dictionary<int, string> CitiesDict = new Dictionary<int, string>()
{
    { 1 ,"Chicago"},
    { 2 ,"New York"},
    { 3 ,"Zimbabwe"},
};
    public PropMgmtViewModel()
    {
        Cities = new SelectList(CitiesDict, "Key", "Value");
    }

查看代码:

 @foreach (var radioitem in Model.Cities)
    {
        @radioitem.Text;
    @Html.RadioButtonFor(model => model.Property.City, radioitem.Value);
    }
        @Html.DropDownListFor(model => model.Property.City, Model.Cities,"Seciniz") 

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-08-06
  • 2014-03-14
  • 2016-07-19
  • 2013-11-24
  • 2012-11-07
  • 2015-04-09
  • 2017-08-26
  • 2017-12-07
相关资源
最近更新 更多