私は以下を使用しています:
XElement select = new XElement("select");
XElement optGroup = null;
if (topics.Count() > 0) {
optGroup = new XElement("optgroup", new XAttribute("label", "Admin"));
optGroup.Add(new XElement("option", new XAttribute("value", "99"), new XText("Select Topic")));
optGroup.Add(new XElement("option", new XAttribute("value", "00"), new XText("All Topics")));
select.Add(optGroup);
foreach (var topic in topics) {
// skip root topic
if (!topic.RowKey.EndsWith("0000")) {
// optgroup
if (topic.RowKey.EndsWith("00")) {
optGroup = new XElement("optgroup", new XAttribute("label", topic.Title));
select.Add(optGroup);
}
// option
else if (optGroup != null) {
optGroup.Add(new XElement("option", new XAttribute("value", topic.RowKey), new XText(topic.Title)));
}
}
}
} else {
optGroup = new XElement("optgroup", new XAttribute("label", "Admin"));
optGroup.Add(new XElement("option", new XAttribute("value", "88"), new XText("No Topics")));
}
return (select.ToString());
変数内の行を処理し、データを使用し<select> ... </select>
て HTML の要素を作成します。
それは機能しますが、必要なのは開始要素と終了要素<select>
ではなく、の内容です。これをアウターではなくコンテンツを返すようにする方法はありますか?<select>
</select>
<select>