Attributes.Add() method in TagBuilder not working inside foreach()

487 Views Asked by At

Attributes.Add() method in TagBuilder not working inside foreach() loop and I am getting this error "There is already an entry with the same key".Also SetInnerText() method and Attributes[key] and property returns only one row inside foraech loop.

var select = new TagBuilder("select");
var option = new TagBuilder("option");

foreach (var country in Countries)
{
    option.Attributes.Add("value",country.Id.ToString());
    option.SetInnerText(country.Country);
}

select.InnerHtml = option.ToString(TagRenderMode.Normal);
select.ToString(TagRenderMode.Normal);
0

There are 0 best solutions below