šŸ“„ IrbyForms/Index.cshtml Documentation


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Model
  4. Key Functional Areas
  5. Third‐Party Integrations
  6. API Endpoints Overview
  7. Error Handling & Return Types
  8. UML Class Diagram
  9. Sample Usage & Code Blocks
  10. Conclusion

1. Overview & Purpose

šŸ“ Index.cshtml is an ASP.NET Core Razor view under the path IrbyImaging/Views/IrbyForms/. It renders a listing page for Irby Forms, allowing users to:

  • View a data‐driven table of available forms.
  • Download individual form files.
  • Leverage DataTables for search, pagination, and responsive design.

This page acts as the front‐end for the IrbyFormsController, binding a collection of IrbyFormsView models to a dynamic table.


2. Dependencies & Technologies

Technology / Library Purpose Source / CDN
ASP.NET Core Razor Server‐side view rendering Built‐in
DataTables (jQuery plugin) Interactive tables (search, sort, paging) https://cdn.datatables.net/
Bootstrap 4 Responsive layout & styling ~/lib/datatables/css/dataTables.bootstrap4.min.css
jQuery DOM manipulation & plugin initialization https://code.jquery.com/jquery-3.5.1.js
DataTables Buttons & Export modules CSV/Excel/PDF export & print functionality https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js etc.
Bootstrap Bundle & Plugins (MetisMenu) UI components & side‐menu ~/libs/bootstrap/js/bootstrap.bundle.min.js, ~/libs/metismenu/metisMenu.min.js, etc.

3. View Model & Data Model

@model IEnumerable<IrbyImaging.UI.Models.IrbyFormsView>

IrbyFormsView (in the UI.Models namespace) must contain at least the following properties:

Property Type Description
FormNumber string Unique identifier for the form
FileName string Display name of the form file
FilePath string Physical or virtual path to file

4. Key Functional Areas

4.1 Page Structure & Layout

  • Bootstrap Grid:
    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-body">
            <h4 class="card-title mb-4">Irby Forms</h4>
            <!-- Table Goes Here -->
          </div>
        </div>
      </div>
    </div>
    
  • Card UI: Title ā€œIrby Formsā€ and the table inside a card body.

4.2 Data Table Rendering

  • Table Markup:
    <table id="formsDatatable" class="table table-striped table-bordered dt-responsive nowrap cell-border" width="100%">
      <thead>…</thead>
      <tfoot>…</tfoot>
      <tbody>
        @foreach(var item in Model) {
          <tr>
            <td>@Html.DisplayFor(m => item.FormNumber)</td>
            <td>@Html.DisplayFor(m => item.FileName)</td>
            <td>@Html.ActionLink("Download", "DownloadForm", "IrbyForms", new { file = item.FilePath }, null)</td>
          </tr>
        }
      </tbody>
    </table>
    
  • Columns:
    Column Description
    Form# Displays FormNumber
    Name Displays FileName
    Download Link to trigger file download
  • Download:

    @Html.ActionLink("Download", "DownloadForm",
      new { controller = "IrbyForms", file = item.FilePath })
    
    • Navigates to IrbyFormsController.DownloadForm(string file).
    • Returns a FileResult for browser download.
  • (Commented Out) View/Print:

    @* Html.ActionLink("View/Print", "ViewAttachment", new { file = item.FilePath }, new { target = "_blank" }) *@
    
    • Placeholder for in‐browser rendering or printing.

4.4 Scripts & DataTables Initialization

  1. CSS Includes (in <head> or before table):
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css" />
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" />
    
  2. JS Includes (in @section Scripts):
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>
    <script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="~/libs/metismenu/metisMenu.min.js"></script>
    <script src="~/libs/simplebar/simplebar.min.js"></script>
    <script src="~/libs/node-waves/waves.min.js"></script>
    
  3. Initialization:
    <script>
      $(document).ready(function() {
        $('#formsDatatable').DataTable({
          processing: true,
          filter: true,
          // Uncomment for export buttons:
          // dom: 'Bfrtip',
          // buttons: ['csv', 'excel', 'print']
        });
      });
    </script>
    

5. Third‐Party Integrations

  • DataTables: Core plugin for table features.
  • Buttons Extension: Enables CSV/Excel/PDF export & print.
  • jsZip & pdfMake: Underpin export functionality.
  • Bootstrap & MetisMenu: Base UI and side‐menu interactions.

6. API Endpoints Overview

Action URL Pattern Return Type Description
Index /IrbyForms/Index ViewResult Renders the forms listing page
DownloadForm /IrbyForms/DownloadForm?file= FileResult Streams the requested file to user
ViewAttachment (TBD) /IrbyForms/ViewAttachment?file= ActionResult Preview or print form (commented)

Note: Controller signatures are inferred.


7. Error Handling & Return Types

  • Model Null/Empty: The foreach loop will render zero rows if the model is empty. Consider adding a no‐data message.
  • File Not Found: DownloadForm should handle missing files and return NotFound() or a user‐friendly message.
  • DataTables Errors: Enabled via "processing": true, view any JS errors in the browser console.

8. UML Class Diagram

classDiagram
    class IrbyFormsView {
      +string FormNumber
      +string FileName
      +string FilePath
    }
    class IrbyFormsController {
      +IActionResult Index()
      +FileResult DownloadForm(string file)
      +IActionResult ViewAttachment(string file)
    }
    IrbyFormsController --|> Microsoft.AspNetCore.Mvc.Controller
    IrbyFormsController ..> IrbyFormsView : uses

9. Sample Usage & Code Blocks

A. Razor View Excerpt

@foreach (var item in Model)
{
  <tr>
    <td>@Html.DisplayFor(m => item.FormNumber)</td>
    <td>@Html.DisplayFor(m => item.FileName)</td>
    <td>
      @Html.ActionLink("Download",
        "DownloadForm",
        "IrbyForms",
        new { file = item.FilePath },
        htmlAttributes: null)
    </td>
  </tr>
}

B. Controller Snippet

public class IrbyFormsController : Controller
{
    public IActionResult Index()
    {
        var forms = _formService.GetAllForms(); // Returns IEnumerable<IrbyFormsView>
        return View(forms);
    }

    [HttpGet]
    public FileResult DownloadForm(string file)
    {
        var path = Path.Combine(_hostingEnv.WebRootPath, file);
        var mime = "application/octet-stream";
        return PhysicalFile(path, mime, Path.GetFileName(path));
    }
}

C. Initializing DataTables with Export Buttons

$('#formsDatatable').DataTable({
    dom: 'Bfrtip',
    buttons: ['csv', 'excel', 'pdf', 'print'],
    processing: true,
    responsive: true
});

10. Conclusion

šŸš€ The Index.cshtml view provides a clean, responsive interface for listing and downloading forms in the IrbyImaging application. Leveraging ASP.NET Core Razor, DataTables, and Bootstrap, users benefit from built‐in search & pagination, while developers can easily extend functionality (e.g., view/print, export options). Follow the patterns above to maintain consistency and handle edge cases such as missing data or files.

Happy coding! šŸŽ‰