0

This is my code. It's just a basic cshtml page (not MVC) that I'm editing in a text editor. Visual Studio doesn't help much, it seems to suffer from the same issues as the compiler.

The code is printing a list of steps in a "plan" into a table, retrieved from a db query. There may be multiple plans, and each time there's a new one I want to display its name in a panel followed by its steps in a table. This means closing the current table and starting a new one.

The compiler doesn't seem to be able to handle the closing tags when they're "out of place". I've tried with and without Html.Raw() and the results are similar. Is there a technique that will work and allow this to compile?

@{
    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>
Tasos K.
  • 7,979
  • 7
  • 39
  • 63
  • Follow the tips found [here](https://stackoverflow.com/questions/9406915/asp-net-how-to-resolve-cs1513-expected-error-on-page) – vfle Aug 28 '18 at 09:14
  • I believe that there is no way around it. Since a `` tag opens in the `foreach` loop, it is expected to find the `
    ` tag inside the loop. You'll need to adjust your markup, which I believe will lead to a cleaner markup as well.
    – Tasos K. Aug 28 '18 at 09:32
  • @vfle yes, thanks I had looked at that thread. – Nick Carrington Aug 28 '18 at 11:14
  • @TasosK. That's a bit like saying "you'll need to write it a different way". But actually, that's what I've done - rewritten it as 2 queries with a foreach loop for each one. Thanks. – Nick Carrington Aug 28 '18 at 11:16
  • I think it's the multine query. Try putting it all in a single line to see if that's the cause. – vfle Aug 28 '18 at 11:18

1 Answers1

0

Fixed by rewriting as 2 queries, one to get the list of plans, the other to list the items within each. Then the tables are fully contained within the foreach loops.