描述:编译服务此请求所需的资源时出错.编译器错误消息:应为CS1513:}

本文关键字:错误 编译器 出错 消息 应为 CS1513 服务 编译 请求 描述 资源 | 更新日期: 2023-09-27 18:26:12

这是我的html代码:

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

错误是说我错过了一个"{",但我不相信这就是

描述:编译服务此请求所需的资源时出错.编译器错误消息:应为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>

或者为了让它更整洁,可以尝试使用字符串。改为格式:

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

但我不相信这就是

你最好相信编译器。我建议你正确地缩进你的代码,因为这样的语法错误很容易看到:

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