📄 Documentation: IrbyImaging/Views/Manufacturers/Create.cshtml


🗂 Table of Contents

  1. Overview & Purpose
  2. MVC Context & Flow
  3. Key Functional Areas
  4. Dependencies & Technologies
  5. View Models & Data Models
  6. Helper Methods & Utilities
  7. Error Handling & Validation
  8. API Endpoints Overview
  9. Third‑party Integrations
  10. Sample Code Blocks
  11. Usage Example & Screenshots
  12. UML Sequence Diagram
  13. Conclusion

1. Overview & Purpose

Create.cshtml is the Razor View responsible for rendering the "New Manufacturer" form in the IrbyImaging ASP.NET Core MVC application. It allows users to:

  • 🆕 Enter details for a new Manufacturer (currently only Name).
  • ✅ Submit the form to persist data.
  • 🔙 Return to the Manufacturers index list.

This view ensures a consistent look‑and‑feel via the shared layout and uses Tag Helpers for strong typing, client‑side validation, and clean syntax.


2. MVC Context & Flow

sequenceDiagram
    participant User
    participant View as Create.cshtml
    participant Controller as ManufacturersController
    participant Service as ManufacturerService
    participant DB as Database

    User->>View: Navigate to /Manufacturers/Create
    View->>User: Renders empty form
    User->>View: Fills fields & clicks "Create"
    View->>Controller: POST /Manufacturers/Create (Model Binding)
    Controller->>Service: Validate & Save
    Service->>DB: INSERT Manufacturer
    DB-->>Service: Acknowledgement
    Service-->>Controller: Return success
    Controller-->>User: Redirect to Index

3. Key Functional Areas

Section Purpose
@model Declaration Binds the view to IrbyImaging.DomainClasses.Manufacturer
ViewData & Layout Sets page Title and uses _ATSLayout.cshtml
<form asp-action="Create"> Posts back to ManufacturersController.Create
Tag Helpers (asp-for) Generates <label>, <input>, <span> with strong typing
Validation Summaries Displays model‑level errors
Buttons Index List (Cancel) & Create (Submit)
Script Inclusions Injects JS libraries & client‑side validation scripts

4. Dependencies & Technologies

Category Technology / Library
Framework ASP.NET Core MVC
View Engine Razor (.cshtml)
CSS / UI Bootstrap 5 (via ~/libs/bootstrap/…)
Menu & Sidebar MetisMenu (metisMenu.min.js)
Custom Scrollbars SimpleBar (simplebar.min.js)
Waves Effect Node Waves (waves.min.js)
Val. Scripts Partial _ValidationScriptsPartial.cshtml
Layout _ATSLayout.cshtml (Shared Shell)

5. View Models & Data Models

Manufacturer Domain Model

namespace IrbyImaging.DomainClasses
{
    public class Manufacturer
    {
        public int    Id   { get; set; }   // PK
        public string Name { get; set; }   // Required
        // … other properties …
    }
}
  • @model Manufacturer at the top of the view binds the form fields to the Manufacturer instance.

6. Helper Methods & Utilities

  1. Tag Helpers

    • asp-for: Binds to model properties
    • asp-action: Points form submission to controller actions
    • asp-validation-summary & asp-validation-for: Render validation messages
  2. Partial Rendering

    @section Scripts {
      @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
    }
    
    • Injects client‑side validation (jQuery Unobtrusive + jQuery Validate).

7. Error Handling & Validation

  • Model-Only Validation Summary

    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    

    Displays errors that apply to the model as a whole (e.g., unique constraint failures).

  • Field-Level Validation

    <span asp-validation-for="Name" class="text-danger"></span>
    

    Renders the error message next to the Name field if validation rules (e.g., [Required]) fail.


8. API Endpoints Overview

Form Element HTTP Method Endpoint Description
<form asp-action=""> POST /Manufacturers/Create Creates a new Manufacturer in the DB
<a asp-action="Index"> GET /Manufacturers/Index Redirects to the manufacturers list view

9. Third‑party Integrations

Library Purpose Path
Bootstrap Bundle Responsive UI & components ~/libs/bootstrap/js/bootstrap.bundle.min.js
MetisMenu Multi‑level sidebar navigation ~/libs/metismenu/metisMenu.min.js
SimpleBar Custom scrollbars ~/libs/simplebar/simplebar.min.js
Node Waves Click‑ripple effect on buttons ~/libs/node-waves/waves.min.js

10. Sample Code Blocks

Full Create.cshtml

@model IrbyImaging.DomainClasses.Manufacturer

@{
    ViewData["Title"] = "Create";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}

<h2>New Manufacturer</h2>
<hr />

<div class="row">
  <div class="col-md-4">
    <form asp-action="Create">
      <div asp-validation-summary="ModelOnly" class="text-danger"></div>

      <div class="form-group">
        <label asp-for="Name" class="control-label"></label>
        <input asp-for="Name" class="form-control" />
        <span asp-validation-for="Name" class="text-danger"></span>
      </div>

      <div class="form-group">
        <a asp-action="Index" class="btn btn-danger irby-red">Index List</a>
        &nbsp;&nbsp;
        <input type="submit" value="Create" class="btn btn-success irby-green" />
      </div>
    </form>
  </div>
</div>

<br /><br />

<!-- JAVASCRIPT -->
<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"); }
}

11. Usage Example & Screenshots

  1. Navigate to /Manufacturers/Create.

  2. Fill the Name field:

    New Manufacturer Form Screenshot

  3. Click Create → Redirects to Index on success, showing updated list.


12. UML Sequence Diagram

sequenceDiagram
    participant Browser
    participant CreateView
    participant Controller
    participant DomainService
    participant Database

    Browser->>CreateView: GET /Manufacturers/Create
    CreateView-->>Browser: HTML form
    Browser->>CreateView: POST data { Name = "Acme" }
    CreateView->>Controller: Bind Model + Validate
    Controller->>DomainService: Save(manufacturer)
    DomainService->>Database: INSERT INTO Manufacturers
    Database-->>DomainService: OK
    DomainService-->>Controller: Success
    Controller-->>Browser: Redirect /Manufacturers/Index

13. Conclusion

  • Create.cshtml is a focused Razor view that leverages ASP.NET Core MVC Tag Helpers for strong‑typed, validated, and clean form rendering.
  • It integrates seamlessly with shared layout and third‑party UI scripts to provide a polished UX.
  • By following the patterns shown here, you can easily extend the form (add more fields, custom validation) or reuse the structure in other parts of the application.

Happy Coding! ✨