📄 ViewDocuments.cshtml Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Models & Data Models
- Key Functional Areas
4.1. Search Form 🔍
4.2. Documents DataTable 📋 - Helper Methods & Utilities
- Error Handling & Validation ❗
- API Endpoints Overview 🔌
- Third‑Party Integrations 🌐
- Sample Code Blocks 💻
- Usage Example 🖱️
- Sequence Diagram 📈
- Conclusion 🎉
1. Overview & Purpose
ViewDocuments.cshtml is a Razor view in the HRImaging area of the IrbyImaging ASP.NET MVC application. It provides an interface for:
- 🔍 Searching documents by upload date and type
- 📋 Listing search results in an interactive DataTable
- 📄 Viewing individual PDF documents in a new browser tab
This page leverages HTML helpers for model binding, client‑side validation, and integrates the popular DataTables plugin for rich tabular interactions.
2. Dependencies & Technologies
| Category | Libraries / Frameworks |
|---|---|
| Server‑Side | ASP.NET MVC 5Razor View Engine |
| Client‑Side | jQueryBootstrap 4DataTables |
| Plugins & Widgets | metisMenusimplebar.jsnode‑waves |
| Exporting | JSZip, pdfmake, DataTables Buttons |
| Scripts Initialization | datatables.init.jsapp.js |
3. View Models & Data Models
DocumentImaging (ViewModel)
The view is strongly typed to IrbyImaging.Models.DocumentImaging, which likely contains:
| Property | Type | Description |
|---|---|---|
DateTime? DocumentUploadedDate |
Date/Nullable | Filter: the date the document was uploaded |
string DocumentType |
String | Filter: type or category of the document |
List<DocumentImaging> SearchResults |
List | Results to display in the DataTable |
| Per‑Item Fields | ||
string DocumentNotes |
String | User notes or name of the document |
string ContentType |
String | MIME type (e.g., application/pdf) |
DateTime DocumentUploadedDate |
DateTime | When the document was uploaded |
string DocumentUploadedBy |
String | Who uploaded the document |
int DocumentImageId |
Int32 (or GUID) | Unique identifier to fetch/view the PDF |
4. Key Functional Areas
4.1. Search Form 🔍
- Purpose: Capture filter criteria and submit to the controller.
- Elements:
- Anti‑Forgery Token for CSRF protection
- Date picker (
<input type="date">) bound toDocumentUploadedDate - Text field for
DocumentType - Validation Summary & Field‑Level Messages
@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>
}
4.2. Documents DataTable 📋
- Rendered only if
Model.SearchResultsis non-null and contains items - Columns:
- Name (DocumentNotes)
- Document Type
- Content Type
- Upload Date
- Upload By
- View (Link to PDF)
@if (Model.SearchResults?.Any() == true) {
<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>@Html.DisplayFor(mItem => item.DocumentNotes)</td>
<td>@Html.DisplayFor(mItem => item.DocumentType)</td>
<td>@Html.DisplayFor(mItem => item.ContentType)</td>
<td>@Html.DisplayFor(mItem => item.DocumentUploadedDate)</td>
<td>@Html.DisplayFor(mItem => item.DocumentUploadedBy)</td>
<td>
@Html.ActionLink(
"View PDF",
"ViewPdf",
"Imaging",
new { id = item.DocumentImageId },
new { target = "_blank", @class = "btn btn-sm btn-outline-secondary" }
)
</td>
</tr>
}
</tbody>
</table>
}
5. Helper Methods & Utilities
| Helper | Purpose |
|---|---|
Html.BeginForm() |
Opens an HTML <form> tag and wires to default action |
Html.AntiForgeryToken() |
Inserts hidden anti‑CSRF token |
Html.ValidationSummary() |
Displays model‑level errors |
Html.TextBoxFor() |
Binds an <input> to a model property |
Html.ValidationMessageFor() |
Renders validation message for a field |
Html.DisplayFor() |
Outputs field value in a read‑only format |
Html.ActionLink() |
Generates anchor tag to an action (ViewPdf) |
6. Error Handling & Validation ❗
- ModelState Validation is surfaced via:
@Html.ValidationSummary(true, ...)for global errors@Html.ValidationMessageFor(...)next to each input
- CSS Class:
.text-dangerto highlight error text
If the model fails validation, the form re-renders with error messages; no search results are shown until valid input is provided.
7. API Endpoints Overview 🔌
| Action | HTTP Verb | Route | Purpose |
|---|---|---|---|
| ViewPdf | GET | /Imaging/ViewPdf/{id} |
Streams the PDF document in a new tab |
| (Search) | POST | (Form Post to same view) | Accepts filters, returns SearchResults |
Note: The form’s
BeginForm()uses default routing to the current HRImaging/ViewDocuments POST action.
8. Third‑Party Integrations 🌐
| Plugin / Library | Use Case |
|---|---|
| jQuery | DOM manipulation, AJAX (if extended) |
| Bootstrap 4 | Grid system, buttons, form styling |
| DataTables | Client‑side sorting, paging, export |
| DataTables Buttons | Export to CSV, PDF, Print, Column visibility |
| JSZip | ZIP support for Excel export |
| pdfmake | PDF export |
| metisMenu | Sidebar/menu interactions |
| simplebar.js | Custom scrollbars |
| node‑waves | Ripple click effects |
Initialization happens in:
<script src="~/js/pages/datatables.init.js"></script>
<script src="~/js/app.js"></script>
9. Sample Code Blocks 💻
Razor: Form Start & Anti‑Forgery
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<!-- fields... -->
}
Razor: DataTable Definition
<table id="datatable-buttons" class="table table-bordered dt-responsive nowrap w-100">
<!-- thead, tbody with @foreach -->
</table>
10. Usage Example 🖱️
- Navigate to HRImaging → View Documents
- Select a Date (e.g., 2023-08-15)
- Enter a Document Type (e.g., "Offer Letter")
- Click Submit
- Browse the Documents List
- Click “View PDF” to open the file in a new window
11. Sequence Diagram 📈
sequenceDiagram
participant User
participant View as ViewDocuments.cshtml
participant Controller as HRImagingController
participant Service as DocumentService
participant DB as Database
User->>View: GET /HRImaging/ViewDocuments
View->>Controller: Render initial form
User->>View: Fill form + Submit
View->>Controller: POST filters
Controller->>Service: searchDocuments(date, type)
Service->>DB: SELECT * FROM Documents WHERE ...
DB-->>Service: List<Document>
Service-->>Controller: passes results
Controller-->>View: Render ViewDocuments with Model.SearchResults
User->>View: Click ViewPdf
View->>Controller: GET /Imaging/ViewPdf/{id}
Controller->>Service: fetchBinary(id)
Service->>DB: SELECT Blob FROM Documents
DB-->>Service: Binary data
Controller-->>Browser: FileStreamResult (application/pdf)
12. Conclusion 🎉
The ViewDocuments.cshtml view provides a user-friendly, searchable, and exportable interface for browsing HR‑related documents. It ties together:
- ASP.NET MVC model binding & validation
- DataTables for rich tabular features
- Bootstrap for responsive design
- Secure interactions via Anti‑Forgery tokens
By following this documentation and the sample code blocks, developers can easily extend the view (e.g., add more filters), customize the DataTable options, or integrate additional export formats.
Happy Coding! 🚀