๐ IrbyImaging/Views/Computers/Details.cshtml Documentation
๐ Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- ViewModel & DataModel
- Layout Configuration
- HTML & Razor Markup Explanation
- 6.1 Page Title & Header
- 6.2 Details Display (
<dl>) - 6.3 Action Buttons
- Helper Methods & Utilities
- Error Handling & Return Types
- Sample Usage & Code Blocks
- UML Diagram
- Thirdโparty Integrations
- Conclusion
1. Overview & Purpose
File: IrbyImaging/Views/Computers/Details.cshtml
Responsibility: Render a detailed, readโonly view of a single Computer record in the ATS (Asset Tracking System).
Primary Features:
- Presents all key properties of a
ComputerDetailViewModel - Applies dynamic styling (e.g., warranty status)
- Links to related data (e.g., owning employee)
- Provides navigation buttons (Index, Edit, History)
This Razor view is part of an ASP.NET MVC flow:
- Controller fetches a computer entity from the database
- Controller builds a
ComputerDetailViewModel - Controller returns
View(model)โ Details.cshtml receives the model
2. Key Functional Areas
| Section | Description |
|---|---|
| ViewData & Layout config | Sets page title and master layout |
| Header | Displays Make & Model + Status |
Detail List (<dl>) |
Shows all properties in a labelโvalue format |
| Owner Link | Navigates to Employees/Details/{id} |
| Notes | Renders multiโline notes in a <pre> block |
| Action Buttons | Index, Update, History links for navigation |
| Script Includes | Loads frontโend JavaScript libraries for UI |
3. Dependencies & Technologies
- ASP.NET Core MVC / Razor: Serverโside rendering
- Bootstrap 5: Styling & buttons
- MetaIsMenu, SimpleBar, NodeโWaves: Interactive sidebar & UI effects
- Custom CSS Classes: e.g.,
irby-red,irby-orange,irby-violet - _ATSLayout.cshtml: Shared layout with header, footer, navigation
4. ViewModel & DataModel
4.1 ComputerDetailViewModel (C#)
public class ComputerDetailViewModel
{
public int Id { get; set; }
public string MakeAndModel { get; set; }
public string Status { get; set; }
public string SerialNumber { get; set; }
public string AssetNumber { get; set; }
public string UnitNumber { get; set; }
public string CpsNumber { get; set; }
public string OperatingSystem { get; set; }
public DateTime PurchaseDate { get; set; }
public DateTime EndOfWarranty { get; set; }
public string WarrantyColorClass { get; set; } // e.g., "text-success" or "text-danger"
public bool NeedsReview { get; set; }
public int OwnerId { get; set; } // FK to Employee
public string OwnerFullName { get; set; }
public string Notes { get; set; }
}
4.2 Database Model (Entity Framework)
Typically mirrored by an Computer entity with relationships:
public Employee Owner { get; set; }- Mapping to DB columns:
SerialNumber,AssetNumber, etc.
5. Layout Configuration
@{
ViewData["Title"] = "Computer Details";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
ViewData["Title"]: Sets the window/tab titleLayout: Points to the shared layout, ensuring consistent header/footer & navigation
6. HTML & Razor Markup Explanation
6.1 Page Title & Header
<h2>
@Html.DisplayFor(m => m.MakeAndModel)
<span style="color:blue">@Model.Status</span>
</h2>
@Html.DisplayFor: Safely encodes and renders the property<span>: Applies inline style to the Status badge
6.2 Details Display (<dl>)
A definition list is used to present labelโvalue pairs:
<dl class="dl-horizontal">
<dt>@Html.DisplayNameFor(m => m.SerialNumber)</dt>
<dd>@Html.DisplayFor(m => m.SerialNumber)</dd>
<!-- ...other fields... -->
<dt>@Html.DisplayNameFor(m => m.EndOfWarranty)</dt>
<dd class="@Model.WarrantyColorClass">
@Html.DisplayFor(m => m.EndOfWarranty)
</dd>
<dt>@Html.DisplayNameFor(m => m.OwnerFullName)</dt>
<dd>
<a asp-controller="Employees" asp-action="Details" asp-route-id="@Model.OwnerId">
@Model.OwnerFullName
</a>
</dd>
<dt>@Html.DisplayNameFor(m => m.Notes)</dt>
<dd><pre>@Model.Notes</pre></dd>
</dl>
Highlights:
DisplayNameFor: Renders the friendly label (from DataAnnotations)- WarrantyColorClass: Dynamically changes text color based on warranty status
- Owner Link: Uses Tag Helpers (
asp-controller,asp-action,asp-route-id)
6.3 Action Buttons
<div>
<a asp-action="Index" class="btn btn-danger irby-red">Index List</a>
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-warning irby-orange">Update</a>
<a asp-action="History" asp-route-id="@Model.Id" class="btn btn-primary irby-violet">History</a>
</div>
- Index: Returns to the Computers list
- Edit: Opens the edit form for the current computer
- History: Shows warranty or service history
7. Helper Methods & Utilities
- ASP.NET Tag Helpers:
asp-action,asp-controller,asp-route-*simplify URL generation Html.DisplayFor/Html.DisplayNameFor: Leverage metadata and formatting- CSS Utility Classes (custom):
irby-red,irby-orange,irby-violetfor brand colors
8. Error Handling & Return Types
- This is a readโonly view; errors (e.g., โNot Foundโ) are handled in the Controller
- Typical pattern in Controllerโs
Details(int id):var computer = await _context.Computers.FindAsync(id); if (computer == null) return NotFound(); var vm = _mapper.Map<ComputerDetailViewModel>(computer); return View(vm); - Razor view assumes
Modelis non-null
9. Sample Usage & Code Blocks
9.1 Controller Action
public async Task<IActionResult> Details(int id)
{
var computer = await _context.Computers
.Include(c => c.Owner)
.FirstOrDefaultAsync(c => c.Id == id);
if (computer == null) return NotFound();
var vm = new ComputerDetailViewModel
{
Id = computer.Id,
MakeAndModel = $"{computer.Make} {computer.Model}",
Status = computer.Status,
SerialNumber = computer.SerialNumber,
AssetNumber = computer.AssetNumber,
UnitNumber = computer.UnitNumber,
CpsNumber = computer.CpsNumber,
OperatingSystem = computer.OperatingSystem,
PurchaseDate = computer.PurchaseDate,
EndOfWarranty = computer.EndOfWarranty,
WarrantyColorClass = (computer.EndOfWarranty < DateTime.Today) ? "text-danger" : "text-success",
NeedsReview = computer.NeedsReview,
OwnerId = computer.Owner.Id,
OwnerFullName = computer.Owner.FullName,
Notes = computer.Notes
};
return View(vm);
}
9.2 Rendering in Browser
<h2>HP EliteBook <span style="color:blue">Active</span></h2>
<h4>Asset ID: 12345</h4>
<dl class="dl-horizontal">
<dt>Serial Number</dt><dd>SN-33445</dd>
<!-- โฆ -->
<dt>End Of Warranty</dt><dd class="text-success">2025-06-30</dd>
<!-- โฆ -->
<dt>Owner Full Name</dt>
<dd><a href="/Employees/Details/7">Jane Doe</a></dd>
<dt>Notes</dt><dd><pre>Assigned to VIP user.</pre></dd>
</dl>
10. UML Diagram
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ComputerDetailViewModel โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ - Id: int โ
โ - MakeAndModel: string โ
โ - Status: string โ
โ - SerialNumber: string โ
โ - AssetNumber: string โ
โ - UnitNumber: string โ
โ - CpsNumber: string โ
โ - OperatingSystem: string โ
โ - PurchaseDate: DateTime โ
โ - EndOfWarranty: DateTime โ
โ - WarrantyColorClass: str โ
โ - NeedsReview: bool โ
โ - OwnerId: int โ
โ - OwnerFullName: string โ
โ - Notes: string โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
11. Thirdโparty Integrations
- Bootstrap (JS & CSS)
- MetisMenu: Sidebar accordion menus
- SimpleBar: Custom scrollbars
- NodeโWaves: Ripple animation effects
<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>
12. Conclusion
๐ฏ Details.cshtml is a focused Razor view designed to present every critical attribute of a computer asset in a clean, userโfriendly format. It leans on ASP.NET Core MVC best practicesโstronglyโtyped ViewModels, Tag Helpers, and shared layoutsโto deliver a maintainable, extensible UI component within the IrbyImaging application.
Happy Coding! ๐