I have working example without the conditional here.
public string RenderPostTags(DMCResultSet resultSet)
{
string output = "";
string filterForm = RenderFilterForm(resultSet);
string pagination = RenderPagination(resultSet);
List<XElement> items = resultSet.items;
foreach(XElement i in items)
{
string tags = "";
if (i.Element("tags") != null)
{
foreach(string tag in i.Element("tags").Elements("tag"))
{
tags += "<a href=\"?tag=" + HttpUtility.UrlEncode(tag) + "\">" + tag + "</a>";
}
}
output += tags;
}
return output;
}
I know just putting a count on it wont work but I've tried several different methods and they haven't worked for me. Could be a syntactical error I'm a total C# noob.
But I need to output adjusted html using a if else conditional similar to this
public string RenderPostTags(DMCResultSet resultSet){
string output = "";
string filterForm = RenderFilterForm(resultSet);
string pagination = RenderPagination(resultSet);
List<XElement> items = resultSet.items;
foreach(XElement i in items){
string tags = "";
if (i.Element("tags") != null) {
int count = 1;
int total = i.Element("tags").Elements("tag").Count;
foreach(string tag in i.Element("tags").Elements("tag")) {
if(count == total){
tags += "<a href=\"?tag=" + HttpUtility.UrlEncode(tag) + "\">" + tag + "</a>";
count++;
}else{
tags += "<a href=\"?tag=" + HttpUtility.UrlEncode(tag) + "\">" + tag +","+ " " + "</a>";
count++;
}
}
}
output += tags;
}
return output;
}
Methods I have tried can be found on this thread. Foreach loop, determine which is the last iteration of the loop
Thank you for any assitance.