首页 > 解决方案 > 错误 CS1513 } 预期。编译器过于挑剔?

问题描述

这是我的代码。这只是我在文本编辑器中编辑的基本 cshtml 页面(不是 MVC)。Visual Studio 并没有太大帮助,它似乎与编译器存在相同的问题。

该代码正在将“计划”中的步骤列表打印到从数据库查询中检索的表中。可能有多个计划,每次有新计划时,我都想在面板中显示其名称,然后在表格中显示其步骤。这意味着关闭当前表并开始一个新表。

当它们“不合适”时,编译器似乎无法处理结束标签。我试过有无Html.Raw(),结果是相似的。有没有一种技术可以工作并允许它编译?

@{
    var db = Database.Open("CADDatabase");
    var count=0;
    var num="0";
    var image="blank";
    var APName="blank";
    // Attached action plan for incident
    var APIncidentQuery=@"select action_plan_name, action_plan_item_types.item_type_eng, pre_mobilisation_flag, instruction_text, isnull(action_plan_active.instruction_information,' ') as instruction_information, item_status_eng
    from action_plan, action_plan_active, action_plan_item_types, action_plan_status
    where action_plan_item_types.item_type=action_plan_active.item_type 
    and action_plan_active.item_status=action_plan_status.item_status 
    and action_plan.action_plan_id=action_plan_active.action_plan_id
    and action_plan_active.eid=(select min(eid) from agency_event where num_1=@0) order by action_plan_active.action_plan_id, active_item_id";
}
<!DOCTYPE html>
<html>
 <head>
   <link rel="stylesheet" href="theme.css">
   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   <title>Process Action Plan</title>
 </head>
 <body>
    <!-- Panel header with search box -->
    <div class="container-fluid ">
        <div class="row no-gutters">
            <div class="col-xs-12">
                <div class="panel panel-default">
                    <div class="panel-heading clearfix">
                        <form method="get" class="col-xs-3">
                            <div class="input-group">
                                <input class="form-control" type="text" placeholder="Event id" name="EventId" size="12">
                                <span class="input-group-btn">
                                    <button class="btn btn-primary" type="submit">Search</button>
                                </span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- Header row -->
        <div class="row no-gutters">
            @foreach(var row in db.Query(APIncidentQuery,Request.QueryString["EventId"])){
                image="Images/ActionPlans/" + @row.item_type_eng + ".png";
                // New plan
                if (row.action_plan_name != APName) {
                    // Close off previous table if there is one
                    if (APName != "blank") {
                        Html.Raw("</tbody></table></div></div>");
                    } 
                    <!-- Start new table -->
                    <div class="col-xs-12">
                        <div class="panel panel-warning">
                            <div class="panel-heading">
                                <div class="plan-header">
                                    <img src="http://swi-hsiv-ps03/UKApps/Images/checklist-warning.png" height="32">
                                    <h3 class="panel-title">Action plan items (@row.action_plan_name)</h3>
                                </div>
                            </div>
                            <!-- Table of results -->
                            <table class="table table-condensed table-striped">
                               <thead>
                                   <tr>
                                       <th>#</th>
                                       <th>Type</th>
                                       <th>Pre-dispatch</th>
                                       <th>Instruction</th>
                                       <th>Additional Info</th>
                                   </tr>
                               </thead>
                               <tbody>
                    <!-- store plan name for next iteration -->
                    @{
                        APName=row.action_plan_name;
                    }
                <!-- Populate new table -->
                } 
                <!-- List Action Plan items -->
                <tr>
                    <td>@row.item_number</td>
                    <td><img src="@image" height="30" title="@row.item_type_eng"></td>
                    @if (row.pre_mobilisation_flag == "Y") {
                        <td><img src="images/ActionPlans/done-red.png" title="Y" height="30"></td>
                    } else {
                        <td><img src="images/ActionPlans/delete-grey.png" title="N" height="30"></td>
                    }
                    <td>@row.instruction_text</td>
                    @if (row.instruction_information.Length > 4 && row.instruction_information.Substring(0,5) == "http:") {
                        <td><a href=@row.instruction_information>Additional information</a></td>
                    } else {
                        <td>@row.instruction_information</td>
                    }
                </tr>
            }
        @{
            Html.Raw("</tbody></table></div></div>");
        }
        </div>
    </div>
</body>
</html>

标签: asp.netrazor

解决方案


通过重写为 2 个查询来修复,一个用于获取计划列表,另一个用于列出每个查询中的项目。然后这些表完全包含在 foreach 循环中。


推荐阅读