📄 IrbyImaging/Views/Issues/Create.cshtml Documentation
Table of Contents
- Overview & Purpose
- File Structure & Location
- Dependencies & Technologies
- View Model & Data Model
- UI Layout & Components
- Tag Helpers Explained
- Form & Validation
- Routing & Actions
- Scripts & Client‑Side Validation
- Sequence Diagram (User Flow)
- Usage Examples
- Conclusion
1. Overview & Purpose 🚀
The Create.cshtml view is part of the Issues feature in the IrbyImaging ASP.NET Core MVC application. Its main goal is to provide an intuitive UI for end users to create a new Issue record by entering the required Description field:
- Renders a form bound to the
IrbyImaging.DomainClasses.Issuemodel. - Provides both server‑side and client‑side validation.
- Utilizes reusable layout (
_HDLayout) and validation partial (_ValidationScriptsPartial).
2. File Structure & Location 📁
IrbyImaging/
└── Views/
└── Issues/
└── Create.cshtml ← (This file)
- Views/Issues/ – Holds all Razor views (Index, Details, Create, Edit, Delete) for the Issues entity.
- Create.cshtml – The “Create” view for adding new Issue entries.
3. Dependencies & Technologies 🔧
| Category | Library / Framework | Purpose |
|---|---|---|
| Server‑side framework | ASP.NET Core MVC | MVC architecture, Razor view engine |
| Styling & Layout | Bootstrap (CSS classes) | Grid system, form styling (.form-control, .btn) |
| Client‑side validation | jQuery Unobtrusive Validation | Validates model fields on the client |
| Razor Tag Helpers | asp-for, asp-action, etc. |
Bind model properties, generate form elements |
| Layout file | _HDLayout.cshtml |
Shared header/footer for consistency |
| Partial view | _ValidationScriptsPartial |
Injects jQuery & validation script references |
4. View Model & Data Model 📦
@model IrbyImaging.DomainClasses.Issue
- DomainClasses.Issue likely has at least these properties:
int Idstring DescriptionDateTime CreatedOn...
This view only exposes the Description field for creation. All other properties are set server‑side (e.g., timestamp, user ID).
5. UI Layout & Components 🎨
@{
Layout = "_HDLayout";
ViewData["Title"] = "Create";
}
<h2>Create</h2>
<h4>Issue</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
… form elements …
</form>
</div>
</div>
<div><a asp-action="Index">Back to List</a></div>
- Layout:
_HDLayoutprovides global navigation, styles, and scripts. - Grid: Bootstrap’s
.rowand.col-md-4center the form and ensure responsiveness. - Headings: Clear page title (
<h2>,<h4>) for accessibility.
6. Tag Helpers Explained 🏷️
| Tag Helper | Usage | Outcome |
|---|---|---|
asp-action="Create" |
<form> tag |
Posts form data to IssuesController.Create (HTTP POST) |
asp-for="Description" |
<input>, <label> |
Binds to Model.Description, generates for and id attributes |
asp-validation-summary |
<div> |
Renders model‑level errors in .text-danger |
asp-validation-for="Description" |
<span> |
Shows field‑specific errors next to input |
7. Form & Validation ✅
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
- Server‑side: ASP.NET Core’s model binding & data annotations on
Issue.Description(e.g.,[Required]) will enforce validation. - Client‑side: jQuery Unobtrusive Validation automatically picks up
<input>data‑attributes and shows errors in<span>. - Summary vs. Field:
- Model-level errors (
asp-validation-summary) - Field-level errors (
asp-validation-for)
- Model-level errors (
8. Routing & Actions ↔️
| HTTP Verb | URL | Controller Action | Description |
|---|---|---|---|
| GET | /Issues/Create | IssuesController.Create() [HttpGet] | Renders this view for new Issue. |
| POST | /Issues/Create | IssuesController.Create(Issue model) [HttpPost] | Processes input, saves to DB. |
| GET | /Issues/Index | IssuesController.Index() | Redirects “Back to List” link. |
Note: Ensure the
IssuesControllerhas corresponding GET & POSTCreateactions, with[ValidateAntiForgeryToken]on POST.
9. Scripts & Client‑Side Validation 📜
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
- Loads the
_ValidationScriptsPartialwhich typically includes:jquery.jsjquery.validate.jsjquery.validate.unobtrusive.js
- Enables live validation feedback as users type.
10. Sequence Diagram (User Flow) 📈
sequenceDiagram
participant U as User
participant B as Browser
participant S as Server
U->>B: Navigate to /Issues/Create
B->>S: GET /Issues/Create
S-->>B: Render Create.cshtml + Model
B-->>U: Display form
U->>B: Fill Description + Click Create
B->>S: POST /Issues/Create (form-data)
S->>S: Model Binding & Validation
alt ModelState.IsValid
S->>Database: Save Issue
S-->>B: Redirect to /Issues/Index
B-->>U: Show List of Issues
else Invalid
S-->>B: Re-render Create.cshtml with errors
B-->>U: Show validation messages
end
11. Usage Examples 💡
1. Navigating to the Create Page
GET https://yourdomain.com/Issues/Create
2. Sample Form POST (cURL)
curl -X POST \
https://yourdomain.com/Issues/Create \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "Description=New%20UI%20Bug"
3. Controller Snippet (for context)
// In IssuesController.cs
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Issue issue)
{
if (!ModelState.IsValid)
return View(issue);
_context.Issues.Add(issue);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
12. Conclusion 🎯
The Create.cshtml view is a concise, user-friendly, and robust component for adding new Issue records in the IrbyImaging application. By leveraging ASP.NET Core MVC’s Razor Tag Helpers, Bootstrap styling, and jQuery validation, it ensures:
- Rapid Development: Minimal boilerplate, high reusability.
- Data Integrity: Server‑ and client‑side checks.
- Consistent UX: Shared layout and form styling.
Feel free to extend this template to include additional fields (e.g., Priority, Category) or integrate rich text editors, file uploads, or AJAX‑powered enhancements as your domain requires. Good luck and happy coding! 🎉