【问题标题】:mvc option with html content带有 html 内容的 mvc 选项
【发布时间】:2016-04-28 11:41:55
【问题描述】:

带有 html 内容的 mvc 选项

如何编写/渲染

 <select>
      <option><span style="">Hi</span></option>
      <option><span style="">Hi1</span></option>
      <option><span style="">Hi2</span></option>
</select>

使用@html.DropDownList()

--------更新-------------

我想在选项中使用 html 格式的文本 当我从模态传递它时,它显示在下拉列表中

<span style="">Hi</span>
<span style="">Hi1</span>
<span style="">Hi2</span>

这里 span style="" 是 html 它不是字符串,并且列表来自控制器

【问题讨论】:

  • 为什么会否决投票?我问错了吗
  • 请检查并编辑您的问题,我们不懂问题。对不起。

标签: asp.net-mvc razor


【解决方案1】:

在代码中使用 SelectItem,在该列表中插入选项,通过将其传递给视图并使用 @Html.DropDownListFor(x => x.SelectItem) 为 Post 上的选定项目提供另一个属性,这是一个简单的示例

@Html.DropDownListFor(model => model.Package.State, new SelectList(
              new List<Object>{ 
                   new { value = 0 , text = "Red"  },
                   new { value = 1 , text = "Blue" },
                   new { value = 2 , text = "Green"}
                },
              "value",
              "text",
               2))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-07
    • 2014-09-24
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多