📄 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

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. ViewModel & Data Model
  4. Layout & Page Title
  5. Form Structure & Tag‑Helpers
  6. Validation & Error Handling
  7. Actions & Buttons
  8. Styling & CSS Classes
  9. Sequence Diagram (Mermaid)
  10. Usage Example
  11. 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:
    • Code
    • Description

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 to GLTypeController.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 ModelState errors (e.g., [Required] on Code/Description) will show in:
    • Summary: at the top (asp-validation-summary)
    • Field‑level: next to each input (asp-validation-for)

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-4 for responsive layout.
  • Form Controls:
    • .form-group, .form-control for spacing and input styling.
  • Buttons:
    • .btn, .btn-success (green), .btn-danger (red).
  • Custom:
    • .irby-red, .irby-green for 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 💡

  1. Navigate to /GLType/Create in your browser.
  2. Enter a unique Code (e.g., GL1001).
  3. Enter a Description (e.g., Accounts Receivable).
  4. Click Create.
    • On success: redirected to the Index list.
    • On failure: errors displayed inline.

11. Conclusion 🏁

  • Create.cshtml is 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!