📝 IrbyImaging/Views/CarrierType/Edit.cshtml Documentation
Table of Contents
- Overview & Purpose
- File Location & Structure
- Dependencies & Technologies
- Key Functional Areas
- Model & Data Bindings
- Form Fields & Tag Helpers
- Validation & Error Handling
- Navigation & Actions
- MVC Flow & Sequence Diagram
- Usage Example
- Conclusion
1. Overview & Purpose
Edit.cshtml is an ASP.NET Core Razor View responsible for creating or editing CarrierType records within the IrbyImaging web application. It leverages MVC’s built‑in tag helpers for:
- Model Binding
- Client & Server-side Validation
- Form Submission
This view sits in the CarrierType folder under Views, and renders a form allowing administrators to manage carriers.
🚀 Intended Use:
- Display a form pre‑populated with an existing
CarrierType(for editing), or blank for creating a new one. - Bind user input back to the
CarrierTypemodel and submit it to theEditaction in theCarrierTypeController.
2. File Location & Structure
IrbyImaging/
└── Views/
└── CarrierType/
└── Edit.cshtml
Key Sections in the Razor File:
- @model Declaration
- ViewData & Layout Setup
- Heading & Horizontal Rule
- Form Section
- Validation Summary
- Carrier Name Field
- IsInactive Checkbox
- Action Buttons
3. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC | Framework for Razor views, controllers, and tag helpers |
Razor Syntax (.cshtml) |
Server‑side templating engine |
Tag Helpers (asp-for, etc.) |
Simplify binding of model properties to HTML elements |
| jQuery Validation & Unobtrusive | Client‑side form validation |
| Bootstrap 3 / 4 CSS classes | Layout (row, col-md-4), forms (form-control, btn) |
Custom CSS (irby-red, etc.) |
Branding and color styling |
| DomainClasses.CarrierType | Strongly‑typed model backing the form |
4. Key Functional Areas
- Model Binding
- Binds
CarrierTypemodel to form inputs.
- Binds
- Validation
- Renders summary and field‑specific errors.
- CRUD Operations
- Submits POST to
Editaction for Create/Update.
- Submits POST to
- Navigation
- Provides a link back to the Index list.
5. Model & Data Bindings
@model IrbyImaging.DomainClasses.CarrierType
CarrierType Model Properties
| Property | Type | Description |
|---|---|---|
| Carrier | string | Name of the carrier (e.g., “FedEx”, “UPS”) |
| IsInactive | bool | Indicates whether the carrier option is disabled |
ℹ️ Note: You can decorate these properties in your domain class with DataAnnotations (e.g.,
[Required],[StringLength(50)]) to drive both server‑ and client‑side validation automatically.
6. Form Fields & Tag Helpers
Form Declaration
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<!-- Carrier Name -->
<div class="form-group">
<label asp-for="Carrier" class="control-label"></label>
<input asp-for="Carrier" id="typeVal" class="form-control" />
<span asp-validation-for="Carrier" class="text-danger"></span>
</div>
<!-- IsInactive Checkbox -->
<div class="form-group">
<label asp-for="IsInactive" class="control-label">
Is Option Available?
</label>
<input asp-for="IsInactive" id="typeVal" class="checkbox-inline" />
<span asp-validation-for="IsInactive" class="text-danger"></span>
</div>
<!-- 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>
</form>
- asp-action="Edit": Posts form data to the
Editaction inCarrierTypeController. - asp-for: Binds input elements to model properties.
- asp-validation-for: Renders validation messages for a specific field.
- asp-validation-summary="ModelOnly": Renders an overall summary of model errors.
7. Validation & Error Handling
✅ Client‑side:
- ASP.NET Core automatically includes unobtrusive validation scripts when you call
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpersand include_ValidationScriptsPartial.cshtmlin your layout. - DataAnnotations on your
CarrierTypeclass (e.g.,[Required]) producedata-valattributes for real‑time validation.
❌ Server‑side:
- On POST, the controller checks
ModelState.IsValid. - If invalid, returns the same view, and the validation summary + field errors appear.
[HttpPost]
public IActionResult Edit(CarrierType model)
{
if (!ModelState.IsValid)
{
// Return with validation messages
return View(model);
}
// Save to database and redirect...
}
8. Navigation & Actions
| Element | Type | Target |
|---|---|---|
| Index List button | <a> |
Redirects to CarrierTypeController.Index() |
| Create/Submit button | <input> |
Submits to CarrierTypeController.Edit(model) (POST) |
💡 Tip: You may want to rename the submit button value from “Create” to “Save” or “Update” to better reflect the Edit context.
9. MVC Flow & Sequence Diagram
sequenceDiagram
participant Browser
participant Ctrl as CarrierTypeController
participant DB as Database
Browser->>Ctrl: GET /CarrierType/Edit/{id?}
note right of Ctrl: id? is optional\n(if missing → new record)
Ctrl->>Browser: render Edit.cshtml (model)
Browser->>Ctrl: POST /CarrierType/Edit (form-data)
activate Ctrl
Ctrl->>Ctrl: Validate ModelState
alt ModelState.IsValid == false
Ctrl->>Browser: re-render Edit.cshtml (with errors)
else
Ctrl->>DB: Create or Update CarrierType
DB-->>Ctrl: success
Ctrl->>Browser: RedirectToAction("Index")
end
deactivate Ctrl
10. Usage Example
-
Navigate to Create New Carrier
GET https://yourdomain.com/CarrierType/Edit- Renders the form with empty fields.
-
Submit New Carrier
POST /CarrierType/Edit Content-Type: application/x-www-form-urlencoded Carrier=“DHL”&IsInactive=false- On success, user is redirected to
/CarrierType/Index.
- On success, user is redirected to
-
Edit Existing Carrier
GET https://yourdomain.com/CarrierType/Edit/5- Renders form pre‑populated with
CarrierTypeID=5. - Submit to update.
- Renders form pre‑populated with
👉 Ensure your controller handles both GET and POST for the Edit action, populates the model on GET, checks ModelState on POST, and persists changes.
11. Conclusion
The Edit.cshtml view in IrbyImaging/Views/CarrierType/ provides a simple, robust UI for administrators to add or edit carrier options in the system. By leveraging ASP.NET Core Tag Helpers, DataAnnotations, and Bootstrap, it ensures a consistent, responsive, and validated form experience.
Feel free to:
- Extend with additional fields (e.g., description, code).
- Localize labels using
asp-for+ resource files. - Customize styling via the shared layout (
_ATSLayout.cshtml).
💡 Happy coding! If you have questions or need further customizations, let me know.