【发布时间】:2020-11-29 17:03:55
【问题描述】:
我有这个结构:
public struct IdandName
{
public IdandName(string id, string name)
{
s_ID = id;
s_Name = name;
}
public string s_ID { get; }
public string s_Name { get; }
};
例如,有一个IdandName 列表,我想在我的网站上显示s_Name 变量并在我的下拉列表中返回s_ID。我该怎么做?我将示例列表中的所有s_ID 分配给ViewBag.id,以便它可以显示在网站上。
这是我的看法:
@Html.LabelFor(model => model.id, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.id, new SelectList(ViewBag.id) )
@Html.ValidationMessageFor(model => model.id, "", new { @class = "text-danger" })
</div>```
【问题讨论】:
标签: c# sql model-view-controller