最終的に、2 つのリストを受け取る html ヘルパー メソッドを作成し、項目ごとに「オプション」タイプの新しいタグを作成し、それを選択リストに追加しました。そうすれば、「disabled="disabled"」などの属性を追加できます。
すっきりしない、すっきりしない。正直なところ、これはひどいコードであり、もっと良い方法があればいいのにと思います。ただし、現時点では私のタスクを完了する時間がないため、次のようにすることになりました。
var fullList = new StringBuilder();
var selectList = new TagBuilder("select");
selectList.Attributes.Add("name", "currencies");
selectList.Attributes.Add("id", "selectCurrency");
foreach (var currency in currencies)
{
var option = new TagBuilder("option") {InnerHtml = currency.Id};
option.Attributes.Add("value", currency.Id);
fullList.AppendLine(option.ToString());
}
var separator = new TagBuilder("option") { InnerHtml = "-------" };
separator.Attributes.Add("disabled", "disabled");
fullList.AppendLine(separator.ToString());
selectList.InnerHtml = fullList.ToString();
より良い方法がある場合は、お知らせください。後でこのタスクを再検討してリファクタリングを行うことができるかもしれません。