π Documentation: ViewDoc.cshtml
Path:
IrbyImaging/Views/IView/ViewDoc.cshtml
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & ThirdβParty Integrations
- View Models & Domain Classes
- Helper Methods & Utilities
- Script & Style References
- Controller Endpoints & Routing
- Sample Usage & Code Snippets
- UML Diagram
- Conclusion
Overview & Purpose
ViewDoc.cshtml is an ASP.NET Core Razor View designed to display the metadata and embedded PDF representation of a scanned or uploaded document.
- Binds to the
IrbyImaging.Models.DocumentImagingmodel. - Uses a legal-themed layout (
_LegalLayout.cshtml). - Dynamically renders index fields (metadata attributes) based on their type.
- Embeds an inline PDF preview via a controller action.
Key Functional Areas
1οΈβ£ Model Binding & Hidden Fields
- Model:
@model IrbyImaging.Models.DocumentImaging - ViewData:
@{ ViewData["Title"] = "View Document"; Layout = "~/Views/Shared/_LegalLayout.cshtml"; var idxList = Model.IndexList; var category = Model.IsLegalDocument ? "legal" : Model.IsSafety ? "safety" : Model.IsIT ? "it" : null; } - Hidden Fields: Preserves document state across postbacks.
@Html.HiddenFor(m => m.DocumentImageId) @Html.HiddenFor(m => m.DocumentType) @Html.HiddenFor(m => m.Page) <!-- ...many more hidden inputs for indexing... -->
2οΈβ£ Dynamic Index/Metadata Rendering
Iterates over Model.IndexList and, based on AttributeType or flags (IsMultiValue, LinkEmployeeData, etc.), renders the appropriate readonly form control.
| AttributeType/Flags | UI Control | Data Source |
|---|---|---|
| Text/Character (single) | <textarea> |
IndexValue |
| Date | <input type="date"> |
IndexValue |
| Number/Currency | <input type="number"> |
IndexValue |
| Boolean | <select> with Yes/No |
MultiValueTypes |
| MultiValue | <select> dropdown |
MultiValueTypes |
| LinkEmployeeData | <select> from EmployeeData |
Model.EmployeeData |
| LinkJobData | <select> from JobData |
Model.JobData |
| LinkCustomerData | <select> from CustomerData |
Model.CustomerData |
| State (special) | <select> from StateData |
Model.StateData |
| Fallback | <textarea> |
IndexValue |
@for (var i = 0; i < idxList.Count; i++)
{
var field = idxList[i];
if (field.AttributeType == AttributeType.Text && !field.IsMultiValue)
{
<textarea disabled asp-for="@idxList[i].IndexValue"></textarea>
}
// ... other conditions ...
}
3οΈβ£ PDF Preview Integration
Embeds a PDF viewer in the right-hand column showing the document:
<embed id="frPDF"
width="100%" height="100%"
src="@Url.Action("EditDocumentPreview","LegalImaging",
new { id = Model.DocumentImageId, category = category })#zoom=FitH"
type="application/pdf" />
- Controller Action:
LegalImagingController.EditDocumentPreview(int id, string category) - Zoom: Fit horizontally to container.
4οΈβ£ Loading Spinner & User Feedback
Provides a modal overlay when saving/processing with a spin.js spinner.
<div id="loading">
<div id="loadingcontent">
<p id="loadingspinner">Saving document. Please wait.....</p>
</div>
</div>
$("#saveDocument").click(function() {
$("#loading").fadeIn();
new Spinner({ /* options */ }).spin(document.getElementById('loading'));
});
π οΈ Dependencies & ThirdβParty Integrations
| Library | Usage |
|---|---|
| Bootstrap | Layout, grid, form styles |
| bootstrap-datepicker.css/js | DatePicker control |
| Dropzone.js | (Referenced) File upload UI |
| Select2 | Enhanced <select> |
| TinyMCE | Rich-text editor capability (if needed) |
| jQuery Repeater | Dynamic nested form groups |
| spin.js | Loading spinner |
π View Models & Domain Classes
DocumentImaging (Model)
public class DocumentImaging
{
public int DocumentImageId { get; set; }
public string DocumentType { get; set; }
public IList<IndexField> IndexList { get; set; }
public bool IsLegalDocument { get; set; }
public bool IsSafety { get; set; }
public bool IsIT { get; set; }
public IEnumerable<SelectListItem> DocumentTypes { get; set; }
public IEnumerable<SelectListItem> EmployeeData { get; set; }
// ... JobData, CustomerData, StateData ...
}
IndexField
public class IndexField
{
public int Id { get; set; }
public string AttributeName { get; set; }
public AttributeType AttributeType { get; set; }
public bool IsMultiValue { get; set; }
public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
public bool LinkEmployeeData { get; set; }
public string IndexValue { get; set; }
// ... other flags ...
}
AttributeType (Enum)
public enum AttributeType
{
Text,
Character,
Date,
Number,
Currency,
Boolean
}
π§ Helper Methods & Utilities
Url.Action(...)β Generates URLs forEditDocumentPreview.- Razor loops / conditionals β Render UI blocks per field definition.
@Html.HiddenFor(...)β Persist hidden form data.select2()β Enhance dropdowns on document ready.
ποΈ Script & Style References
@section styles {
<link href="~/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" />
<link href="~/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />
}
<!-- Core JS -->
<script src="~/libs/jquery/jquery.min.js"></script>
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/libs/simplebar/simplebar.min.js"></script>
<script src="~/libs/node-waves/waves.min.js"></script>
<!-- Plugins -->
<script src="~/libs/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="~/libs/tinymce/tinymce.min.js"></script>
<script src="~/libs/jquery.repeater/jquery.repeater.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<!-- Custom -->
<script src="~/js/app.js"></script>
<script>
$(function() { $('.js-example-basic-single').select2(); });
</script>
π¦ Controller Endpoints & Routing
| Action Method | Route / URL | Purpose |
|---|---|---|
Edit(int id) |
/LegalImaging/Edit |
Receives posted metadata |
EditDocumentPreview(int id, string category) |
/LegalImaging/EditDocumentPreview?id={id}&category={category} |
Returns PDF stream |
Usage in Controller
public IActionResult ViewDoc(int id)
{
var model = _documentService.GetDocumentImagingById(id);
return View("ViewDoc", model);
}
π» Sample Usage & Code Snippets
Invoking the View from a Controller
public IActionResult Details(int documentId)
{
var docModel = _repo.FetchDocument(documentId);
return View("ViewDoc", docModel);
}
Example Model Instantiation
var model = new DocumentImaging {
DocumentImageId = 123,
DocumentType = "Contract",
IsLegalDocument = true,
IndexList = new List<IndexField> {
new IndexField {
Id = 1,
AttributeName = "ContractNumber",
AttributeType = AttributeType.Text,
IndexValue = "CN-4567"
},
new IndexField {
Id = 2,
AttributeName = "EffectiveDate",
AttributeType = AttributeType.Date,
IndexValue = DateTime.Today.ToString("yyyy-MM-dd")
}
},
DocumentTypes = GetSelectList(...),
// EmployeeData, JobData, CustomerData, StateData...
};
UML Diagram
classDiagram
class DocumentImaging {
+int DocumentImageId
+string DocumentType
+bool IsLegalDocument
+bool IsSafety
+bool IsIT
+IList~IndexField~ IndexList
}
class IndexField {
+int Id
+string AttributeName
+AttributeType AttributeType
+bool IsMultiValue
+string IndexValue
}
class AttributeType {
<<enumeration>>
+Text
+Character
+Date
+Number
+Currency
+Boolean
}
DocumentImaging "1" o-- "*" IndexField
π― Conclusion
ViewDoc.cshtml offers a fully dynamic, readonly interface for visualizing document metadata and embedded PDF previews.
- Extensible: Easily add new
AttributeTypecases or link data sources. - Integrated: Leverages popular UI libraries (Bootstrap, Select2, TinyMCE).
- User Experience: Provides instant PDF rendering + loading spinner for feedback.
With this guide, you should be able to customize, extend, and integrate the ViewDoc view into your document management workflows. π