📄 ViewDocuments.cshtml Documentation

File Path: IrbyImaging/Views/AccountingImaging/ViewDocuments.cshtml
Technology Stack: ASP.NET MVC Razor View, jQuery, Bootstrap, DataTables, MetisMenu, SimpleBar, Waves, JSZip, PdfMake


📑 Table of Contents

  1. Overview & Purpose
  2. Page Layout & Razor Syntax
  3. Data Binding & View Model
  4. Search Filters Form 🔍
  5. Search Results Table 🗂️
  6. Action Links & Routing 🌐
  7. Validation & Error Handling 🚨
  8. Scripts & Dependencies 🛠️
  9. UML Class Diagram 📊
  10. Usage Example 💡
  11. Conclusion 🎯

1. Overview & Purpose

This Razor view renders a Document Search page under the AccountingImaging area.

  • 🔍 Search Filters: Allows users to filter documents by Date and Type.
  • 🗂️ Results Table: Displays matching records in an interactive DataTable.
  • 📄 View PDF: Each result includes a link to view/download the document as PDF.

It is typically invoked by two controller actions:

  • GET → Show empty search form.
  • POST → Process filters, populate Model.SearchResults, re‑render view.

2. Page Layout & Razor Syntax

@model IrbyImaging.Models.DocumentImaging

@{
    ViewData["Title"] = "Documents Page";
    // Optional: Uncomment to use a custom layout
    // Layout = "~/Views/Shared/_LegalLayout.cshtml";
}
  • @model: Strongly‑typed to DocumentImaging.
  • Sets ViewData["Title"] for the <title> tag.
  • Commented Layout override is available if a specialized layout is required.

3. Data Binding & View Model

ViewModel: IrbyImaging.Models.DocumentImaging

public class DocumentImaging {
    public int DocumentImageId { get; set; }
    public DateTime? DocumentUploadedDate { get; set; }
    public string DocumentType { get; set; }
    public string DocumentNotes { get; set; }
    public string ContentType { get; set; }
    public string DocumentUploadedBy { get; set; }

    // Used to render results
    public List<DocumentImaging> SearchResults { get; set; }
}
  • Input properties (DocumentUploadedDate, DocumentType) drive the search form.
  • SearchResults holds query results for table rendering.

4. Search Filters Form 🔍

@using (Html.BeginForm()) {
  @Html.AntiForgeryToken()
  @Html.ValidationSummary(true, "", new { @class = "text-danger" })

  <div class="row">
    <div class="col-md-4 input-group">
      <span class="input-group-addon">
        <label class="col-form-label col-lg-2">Date</label>
      </span>
      @Html.TextBoxFor(m => m.DocumentUploadedDate, "{0:d}", new { type = "date" })
      @Html.ValidationMessageFor(m => m.DocumentUploadedDate, "", new { @class = "text-danger" })
    </div>
  </div>

  <div class="row">
    <div class="col-md-4 input-group">
      <span class="input-group-addon">
        <label class="col-form-label col-lg-2">Type</label>
      </span>
      @Html.TextBoxFor(m => m.DocumentType)
      @Html.ValidationMessageFor(m => m.DocumentType)
    </div>
  </div>

  <div class="row justify-content-end">
    <div class="col-lg-10">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
  </div>
}

Key Points:

  • Html.BeginForm(): Posts back to same action by default.
  • AntiForgeryToken: Protects against CSRF.
  • Bootstrap classes for responsive layout.
  • TextBoxFor with type="date" for HTML5 date picker.

5. Search Results Table 🗂️

@if (Model.SearchResults?.Any() == true) {
  <div class="row">
    <div class="col-12">
      <div class="card">
        <div class="card-body">
          <h4 class="card-title">Documents List</h4>
          <table id="datatable-buttons" class="table table-bordered dt-responsive nowrap w-100">
            <thead>
              <tr>
                <th>Name</th>
                <th>Document Type</th>
                <th>Content Type</th>
                <th>Upload Date</th>
                <th>Upload By</th>
                <th>View</th>
              </tr>
            </thead>
            <tbody>
              @foreach (var item in Model.SearchResults) {
                <tr>
                  <td>@item.DocumentNotes</td>
                  <td>@item.DocumentType</td>
                  <td>@item.ContentType</td>
                  <td>@item.DocumentUploadedDate?.ToShortDateString()</td>
                  <td>@item.DocumentUploadedBy</td>
                  <td>
                    @Html.ActionLink("View PDF", "ViewPdf", "AccountingImaging", new { id = item.DocumentImageId }, new { target = "_blank" })
                  </td>
                </tr>
              }
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
}

Highlights:

  • Uses DataTables plugin (id="datatable-buttons") for sorting, paging, exporting.
  • Renders one row per SearchResults item.
  • ActionLink opens the PDF in a new tab (target="_blank").

Link Text Controller Action Route Values Target
View PDF AccountingImaging ViewPdf { id = DocumentImageId } _blank
  • Ensure your AccountingImagingController contains:
    public ActionResult ViewPdf(int id) {
        // Fetch document bytes and content-type
        return File(fileBytes, contentType);
    }
    

7. Validation & Error Handling 🚨

  • @Html.ValidationSummary(true) displays model-level errors.
  • @Html.ValidationMessageFor shows field‑specific errors.
  • Relies on DataAnnotations in the DocumentImaging model (e.g., [Required], [DataType(DataType.Date)]).

8. Scripts & Dependencies 🛠️

Below is a summary of client-side libraries:

Library Path Purpose
jQuery ~/libs/jquery/jquery.min.js DOM manipulation, AJAX
Bootstrap Bundle ~/libs/bootstrap/js/bootstrap.bundle.min.js UI components, responsive grid
MetisMenu ~/libs/metismenu/metisMenu.min.js Sidebar menu plugin
SimpleBar ~/libs/simplebar/simplebar.min.js Custom scrollbars
Waves ~/libs/node-waves/waves.min.js Ripple effects
DataTables Core ~/libs/datatables.net/js/jquery.dataTables.min.js~/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js Table enhancements
DataTables Buttons ~/libs/datatables.net-buttons/js/dataTables.buttons.min.js~/libs/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js~/libs/jszip/jszip.min.js~/libs/pdfmake/build/pdfmake.min.js~/libs/pdfmake/build/vfs_fonts.js~/libs/datatables.net-buttons/js/buttons.html5.min.js~/libs/datatables.net-buttons/js/buttons.print.min.js~/libs/datatables.net-buttons/js/buttons.colVis.min.js Export to CSV, PDF, print, column visibility
DataTables Responsive ~/libs/datatables.net-responsive/js/dataTables.responsive.min.js~/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js Mobile-friendly tables
Init Scripts ~/js/pages/datatables.init.js~/js/app.js Custom initialization & application logic

Usage Example (bottom of page):

<script src="~/libs/jquery/jquery.min.js"></script>
<!-- ... other scripts ... -->
<script src="~/js/pages/datatables.init.js"></script>
<script src="~/js/app.js"></script>

9. UML Class Diagram 📊

classDiagram
    class DocumentImaging {
        +int DocumentImageId
        +DateTime? DocumentUploadedDate
        +string DocumentType
        +string DocumentNotes
        +string ContentType
        +string DocumentUploadedBy
        +List~DocumentImaging~ SearchResults
    }
  • DocumentImaging acts as both search criteria and result container.

10. Usage Example 💡

// GET: AccountingImaging/ViewDocuments
public ActionResult ViewDocuments() {
    var model = new DocumentImaging();
    return View(model);
}

// POST: AccountingImaging/ViewDocuments
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ViewDocuments(DocumentImaging model) {
    model.SearchResults = _repo.FindDocuments(
        date: model.DocumentUploadedDate,
        type: model.DocumentType
    );
    return View(model);
}

// GET: AccountingImaging/ViewPdf/{id}
public ActionResult ViewPdf(int id) {
    var doc = _repo.GetById(id);
    return File(doc.Bytes, doc.ContentType);
}
  1. User navigates to /AccountingImaging/ViewDocuments.
  2. Enters Date and/or Type, clicks Submit.
  3. POST action queries repository, fills SearchResults.
  4. View re‑renders, DataTable appears with View PDF links.

11. Conclusion 🎯

The ViewDocuments.cshtml Razor view provides a robust, user‑friendly interface for searching and viewing accounting‐related documents. Leveraging ASP.NET MVC model binding, client‐side validation, and the rich feature set of DataTables, it delivers:

  • 🔍 Efficient Filtering by Date/Type
  • 🗂️ Interactive Results Table with sorting, paging, exporting
  • 📄 On‑the‑fly PDF Viewing in a new browser tab
  • 🚨 Built‑in Validation and CSRF Protection

By following this documentation, developers can quickly understand, maintain, or extend the functionality—adding new filters, customizing the table, or integrating additional export formats. Happy coding! 🚀