Don't add comma

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am using the following code to display some data on an Asp.Net MVC
view:

<%foreach (Level level in theme.Levels)
{%>
<%=level.Description%>,
<%data += level.Type.ToString() + ",";%>
<%}%><br />

How can I avoid having a comma at the end both in
<%=level.Description%>,
and in
<%data += level.Type.ToString() + ",";%>

Thanks,
Miguel
 
shapper said:
Hello,

I am using the following code to display some data on an Asp.Net MVC
view:

<%foreach (Level level in theme.Levels)
{%>
<%=level.Description%>,
<%data += level.Type.ToString() + ",";%>
<%}%><br />

How can I avoid having a comma at the end both in
<%=level.Description%>,
and in
<%data += level.Type.ToString() + ",";%>

Thanks,
Miguel

I would recomment to put the code in code behind instead of in the page,
that makes it easier to write and debug. It looks like ASP code that
tries desperately to survive in the .NET world...

In the markup:

<asp:Literal id="literalLevels" runat="server" />

In the code:

StringBuilder levels = new StringBuilder();
StringBuilder data = new StringBuilder();
bool first = true;
foreach (Level level in theme.Levels) {
if (first) {
first = false;
} else {
levels.Append(",<br />");
data.Append(",");
}
levels.Append(level.Description);
data.Append(level.Type);
}
literalLevels.Text = levels.ToString();
 
I would recomment to put the code in code behind instead of in the page,
that makes it easier to write and debug. It looks like ASP code that
tries desperately to survive in the .NET world...

lol ... not it is not. It is ASP.NET MVC Beta ...
.... it might look old ASP but it is quite away from it ...

I used ASP.NET Forms for a long time but I don't like it very much for
many reasons ...
 
Back
Top