📱 IrbyImaging – Views/MobileDevices/Create.cshtml Documentation
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- ViewModel & Data Models
- Layout & ViewData Configuration
- Form Structure & Key Functional Areas
- 5.1 Validation Summary
- 5.2 Form Fields & Bindings
- 5.3 Action Buttons
- Error Handling & Modals
- Client-Side Scripts & Utilities
- Third-Party Integrations
- Sample Usage & Controller Interaction
- UML Diagram – ViewModel Class
- Conclusion & Best Practices
1. Overview & Purpose
File: IrbyImaging/Views/MobileDevices/Create.cshtml
Purpose:
This Razor View renders the “Create Mobile Device” form in the IrbyImaging web application. It allows users to input details about a new mobile device asset—such as serial number, carrier, purchase date, owner, and more—and submit them back to the server for persistence.
Key features:
- Dynamic dropdowns (Model list, Carrier, Owner, Status)
- Data annotations for validation
- Integration with Site-wide layout and styling
- Error display via modal partial
2. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC Razor | Server-side templating with Tag Helpers |
Tag Helpers (asp-for, asp-items, asp-action) |
Model binding & form generation |
| Bootstrap 4/5 | Responsive grid & form styling |
| MetisMenu, SimpleBar, Waves | UI interactions & custom scrollbars |
Partial Views (_ValidationScriptsPartial, _ErrorModalPartial, _ErrorModalScriptsPartial) |
Reusable components for validation & error modals |
| HTML5 & CSS3 | Standard markup & styling |
3. ViewModel & Data Models
This view is strongly typed to:
@model MobileDeviceCreateViewModel
Key Properties in MobileDeviceCreateViewModel:
| Property | Type | Description |
|---|---|---|
| Type | DeviceType (enum) | Device category (e.g., Tablet, Phone, etc.) |
| IsTelogis | bool | Indicates if Telogis tracking is enabled |
| ModelId | int | Selected Device Model ID |
| ModelList | IEnumerable | Dropdown items for device models |
| SerialNumber | string | Unique device serial number |
| Carrier | Carrier (enum) | Wireless carrier (Verizon, AT&T, etc.) |
| PhoneNumber | string | SIM’s phone number |
| Imei | string | International Mobile Equipment Identity |
| Sim | string | SIM card number |
| PurchaseDate | DateTime | Date of purchase |
| OwnerId | int | Asset owner (Employee) ID |
| OwnerList | IEnumerable | Dropdown items for owners |
| Status | AssetStatus (enum) | Asset status (Active, Retired, etc.) |
| NeedsReview | bool | Flag for quality review |
| Notes | string | Additional remarks |
| ErrorMessage | string | Server-side error to display (if any) |
4. Layout & ViewData Configuration
@{
ViewData["Title"] = "Create";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
- ViewData["Title"] sets the browser tab title to “Create”.
- Layout refers to the shared master page
_ATSLayout.cshtml, ensuring a consistent header, footer, and navigation across the site.
5. Form Structure & Key Functional Areas
5.1 Validation Summary
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
- Renders a summary of validation errors belonging exclusively to the model (excludes property-level messages).
5.2 Form Fields & Bindings
| Field | Tag Helper | Description |
|---|---|---|
| IsTelogis | <input asp-for="IsTelogis" type="checkbox" /> |
Checkbox: Telogis tracking flag |
| ModelId | <select asp-for="ModelId" asp-items="Model.ModelList"> |
Dropdown: selects a device model |
| SerialNumber | <input asp-for="SerialNumber" /> |
Text input: unique serial number |
| Carrier | <select asp-for="Carrier" asp-items="@Html.GetEnumSelectList<Carrier>().OrderBy(e=>e.Text)"> |
Dropdown: selects the carrier |
| PhoneNumber | <input asp-for="PhoneNumber" /> |
Text input: phone number |
| Imei | <input asp-for="Imei" /> |
Text input: IMEI string |
| Sim | <input asp-for="Sim" /> |
Text input: SIM card number |
| PurchaseDate | <input asp-for="PurchaseDate" /> |
Date input: purchase date |
| OwnerId | <select asp-for="OwnerId" asp-items="Model.OwnerList"> |
Dropdown: selects owner |
| Status | <select asp-for="Status" asp-items="@(Html.GetEnumSelectList<AssetStatus>().Where(e=>e.Text!="All"))"> |
Dropdown: asset status |
| NeedsReview | <input asp-for="NeedsReview" type="checkbox" /> |
Checkbox: review required |
| Notes | <textarea asp-for="Notes"></textarea> |
Multiline text area for extra notes |
Note: A hidden or commented-out
<div id="typeDiv">is present for a future enhancement to show/hide theTypeselector when certain categories are chosen.
5.3 Action Buttons
<div class="form-group">
<a asp-action="Index" class="btn btn-danger irby-red">Index List</a>
<input type="submit" value="Create" class="btn btn-success irby-green" />
</div>
- Index List: Redirects back to the list view.
- Create: Submits the form to the
CreatePOST action in theMobileDevicescontroller.
6. Error Handling & Modals
@if (!string.IsNullOrEmpty(Model.ErrorMessage)) {
await Html.RenderPartialAsync("_ErrorModalPartial");
}
- If the controller sets
Model.ErrorMessage, the view renders a modal partial (_ErrorModalPartial) to display the error. - Corresponding scripts are loaded in the Scripts section via
_ErrorModalScriptsPartial.
7. Client-Side Scripts & Utilities
<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>
@section Scripts {
await Html.RenderPartialAsync("_ValidationScriptsPartial");
await Html.RenderPartialAsync("_ErrorModalScriptsPartial");
@* Future JS to toggle Type dropdown *@
}
- Bootstrap Bundle: Responsive behaviors, modals, and form controls.
- MetisMenu: Vertical menu handling.
- SimpleBar: Custom scrollbar styling.
- Waves: Ripple effect on buttons.
- ValidationScriptsPartial: jQuery Unobtrusive Validation for client-side checks.
- ErrorModalScriptsPartial: Triggers the error modal dialog.
Tip: There are commented-out jQuery snippets intended to toggle the Type selector, demonstrating how to extend client logic.
8. Third-Party Integrations
- 🟢 Bootstrap for UI
- 🟢 jQuery Unobtrusive Validation (via
_ValidationScriptsPartial) - 🟢 MetisMenu, SimpleBar, Waves for advanced UI effects
9. Sample Usage & Controller Interaction
Controller (Excerpt)
public class MobileDevicesController : Controller
{
// GET: /MobileDevices/Create
public IActionResult Create()
{
var vm = new MobileDeviceCreateViewModel {
ModelList = _deviceService.GetModels(),
OwnerList = _employeeService.GetOwners(),
// other defaults...
};
return View(vm);
}
// POST: /MobileDevices/Create
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(MobileDeviceCreateViewModel model)
{
if (!ModelState.IsValid) {
// repopulate dropdowns
model.ModelList = _deviceService.GetModels();
model.OwnerList = _employeeService.GetOwners();
return View(model);
}
var result = _deviceService.AddDevice(model);
if (!result.Success) {
model.ErrorMessage = result.ErrorMessage;
return View(model);
}
return RedirectToAction(nameof(Index));
}
}
Workflow
- GET
/MobileDevices/Create→ renders form. - User fills in fields & clicks Create.
- POST
/MobileDevices/Create→ server validates →- On error: shows same form with validation messages or error modal.
- On success: redirects to Index.
10. UML Diagram – ViewModel Class
classDiagram
class MobileDeviceCreateViewModel {
+DeviceType Type
+bool IsTelogis
+int ModelId
+IEnumerable<SelectListItem> ModelList
+string SerialNumber
+Carrier Carrier
+string PhoneNumber
+string Imei
+string Sim
+DateTime PurchaseDate
+int OwnerId
+IEnumerable<SelectListItem> OwnerList
+AssetStatus Status
+bool NeedsReview
+string Notes
+string ErrorMessage
}
11. Conclusion & Best Practices
- ✅ Strongly‑typed views ensure compile‑time safety.
- ✅ Tag Helpers (
asp-for,asp-items) dramatically reduce boilerplate. - ✅ Partial views for validation and error modals maintain DRY principles.
- ⚙️ Future enhancement: uncomment the
typeDivand associated JavaScript to dynamically show/hide the Device Type selector. - 🛡️ Security: Always keep
[ValidateAntiForgeryToken]on POST actions for CSRF protection.
🎉 That’s it! You now have a thorough understanding of the Create.cshtml view for Mobile Devices in the IrbyImaging application: its structure, data flow, dependencies, and how it integrates into the broader MVC pattern.