📄 Documentation: IrbyImaging/Views/GLType/Create.cshtml
File Path:
IrbyImaging/Views/GLType/Create.cshtml
Purpose: Render a form to create a new General Ledger (GL) record.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- ViewModel & Data Model
- Layout & Page Title
- Form Structure & Tag‑Helpers
- Validation & Error Handling
- Actions & Buttons
- Styling & CSS Classes
- Sequence Diagram (Mermaid)
- Usage Example
- Conclusion
1. Overview & Purpose 🚀
This Razor View is part of the General Ledger Type (GLType) feature in the IrbyImaging application. It provides an HTML form that allows users to input and submit a new GL Record (account code and description). On submission, it posts the data to the Create action of the GLType controller for processing and persistence.
2. Dependencies & Technologies 🛠️
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC Razor | Server‑side view rendering |
Tag Helpers (asp-for, etc.) |
Simplify model binding and URL generation |
| jQuery & Unobtrusive Validation | Client‑side form validation |
| Bootstrap 4 (CSS) | Layout grid, form styling and responsive design |
_ATSLayout.cshtml |
Shared layout containing header, footer, nav, etc. |
Note: Ensure ViewImports.cshtml includes
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3. ViewModel & Data Model 📋
Model Type:
namespace IrbyImaging.DomainClasses
{
public class GeneralLedger
{
public int Id { get; set; }
public string Code { get; set; }
public string Description{ get; set; }
// ...other properties...
}
}
- Model Binding: The view is strongly typed to
GeneralLedger. - Fields Used:
CodeDescription
4. Layout & Page Title 🖼️
@{
ViewData["Title"] = "Create";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
- ViewData["Title"]: Sets the
<title>tag of the page to “Create”. - Layout: Inherits common UI (header/nav/footer) from
_ATSLayout.cshtml.
5. Form Structure & Tag‑Helpers 🏗️
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Code" class="control-label"></label>
<input asp-for="Code" id="typeVal" class="form-control" />
<span asp-validation-for="Code" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" id="typeVal" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<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="Create": Posts toGLTypeController.Create(HTTP POST).asp-for: Binds labels, inputs, and validation spans to model properties.asp-validation-summary="ModelOnly": Renders model‑level errors only.
6. Validation & Error Handling ✅ / ❌
- Client‑side validation relies on jQuery Unobtrusive Validation.
- Server‑side validation: Any
ModelStateerrors (e.g.,[Required]onCode/Description) will show in:- Summary: at the top (
asp-validation-summary) - Field‑level: next to each input (
asp-validation-for)
- Summary: at the top (
7. Actions & Buttons 🎯
| Button/Text | Type | Action | Style Class |
|---|---|---|---|
| Index List | <a> |
Links to Index (List view) |
btn btn-danger |
| Create | <input> |
Submits form to Create (POST) |
btn btn-success |
- Navigation: “Index List” returns you to the main list of GL Types without saving.
8. Styling & CSS Classes 🎨
- Bootstrap Grid:
.row&.col-md-4for responsive layout.
- Form Controls:
.form-group,.form-controlfor spacing and input styling.
- Buttons:
.btn,.btn-success(green),.btn-danger(red).
- Custom:
.irby-red,.irby-greenfor brand‑specific colors.
9. Sequence Diagram (Mermaid) 📈
sequenceDiagram
participant U as User
participant V as Create.cshtml
participant C as GLTypeController
U->>C: GET /GLType/Create
C-->>V: Returns Create view (empty GeneralLedger model)
U->>V: Fills form (Code, Description)
U->>C: POST /GLType/Create with form data
C->>C: Validate ModelState
alt valid
C->>DB: Save GeneralLedger
C->>U: Redirect to /GLType/Index
else invalid
C-->>V: Return view with ModelState errors
end
10. Usage Example 💡
- Navigate to
/GLType/Createin your browser. - Enter a unique Code (e.g.,
GL1001). - Enter a Description (e.g.,
Accounts Receivable). - Click Create.
- On success: redirected to the Index list.
- On failure: errors displayed inline.
11. Conclusion 🏁
Create.cshtmlis a clean, tag‑helper driven form for adding new GL records.- Leverages ASP.NET Core MVC conventions and Bootstrap for a consistent, responsive UI.
- Validation is handled on both client and server.
- Easily extendable: add new fields, custom validation messages, or additional form logic as needed.
Happy Coding! 😊
Questions or feedback? Reach out to the IRBY Imaging dev team!