š IrbyForms/Index.cshtml Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model & Data Model
- Key Functional Areas
- ThirdāParty Integrations
- API Endpoints Overview
- Error Handling & Return Types
- UML Class Diagram
- Sample Usage & Code Blocks
- 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 FormNumberName Displays FileNameDownload Link to trigger file download
4.3 Action Links (Download)
-
Download:
@Html.ActionLink("Download", "DownloadForm", new { controller = "IrbyForms", file = item.FilePath })- Navigates to
IrbyFormsController.DownloadForm(string file). - Returns a FileResult for browser download.
- Navigates to
-
(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
- 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" /> - 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> - 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
foreachloop will render zero rows if the model is empty. Consider adding a noādata message. - File Not Found:
DownloadFormshould handle missing files and returnNotFound()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! š