2012-02-29 74 views
1

这是我的html代码:描述:在编译为请求提供服务所需的资源编译期间发生错误。编译器错误信息:CS1513:}预期

<span> 
<%if (Model.Data.Service.Attachments.Count > 0) 
{ 

%><h3>Downloads for your service:</h3> <% 

foreach (var attach in Model.Data.Service.Attachments) 
{ 
    %><%=attach.Name%>: https://<%= Request.Url.Host%> "/File/Download/" <%= attach.Id.ToString()%><br /> 
}<% 

}%></span> 

错误是说我缺少一个“{”,但我不认为这是什么回事

回答

1

您的foreach的右括号不在<%%>块。它需要:

<span> 
<%if (Model.Data.Service.Attachments.Count > 0) 
{ 

%><h3>Downloads for your service:</h3> <% 

foreach (var attach in Model.Data.Service.Attachments) 
{ 
%><%=attach.Name%>: https://<%= Request.Url.Host%> "/File/Download/" <%= attach.Id.ToString()%><br /> 
<% } 

}%></span> 

还是要使它有点整洁尝试使用的String.format来代替:

<span> 
<%if (Model.Data.Service.Attachments.Count > 0) 
{ 
%><h3>Downloads for your service:</h3> <% 
foreach (var attach in Model.Data.Service.Attachments) 
{ 
    %><%= string.Format("{0}: https://{1}/File/Download/{2}", attach.Name, Request.Url.Host, attach.Id) %><br /> 
<%} 
}%></span> 
+0

,这里不是问题。他有语法错误。 – 2012-02-29 15:45:32

+0

已更新为包含解决方案。 – 2012-02-29 15:47:59

+0

您的string.Format片段仍然存在错误。 – 2012-02-29 15:49:02

1

但我不认为这是什么回事

你最好相信编译器。我建议你适当地缩进您的代码,这样的语法错误很容易看出:

<span> 
<% if (Model.Data.Service.Attachments.Count > 0) { %> 
    <h3>Downloads for your service:</h3> 
    <% foreach (var attach in Model.Data.Service.Attachments) { %> 
     <%= attach.Name %>: https://<%= Request.Url.Host %> "/File/Download/" <%= attach.Id.ToString() %> 
     <br /> 
    <% } %> 
<% } %> 
</span>