Don't add comma

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
 
G

Göran Andersson

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();
 
S

shapper

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 ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top