π ViewCrews.cshtml Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Model & Data Structures
- Layout & Razor Structure
- Key Functional Areas
5.1. Search Section π
5.2. Result Grid Section π
5.3. Create New Crew π
5.4. Actions Template βοΈποΈ
5.5. Delete Confirmation Modal β
5.6. Anti-Forgery Token π - JavaScript Functionality π§©
6.1. Initialization
6.2. Search & Clear Handlers
6.3. Create Crew Redirect
6.4. Edit Crew
6.5. Delete Crew Workflow - Styling & Responsive Design π¨
- API Endpoints Overview π
- Sample Code Blocks
- Usage Flow Example
- UML Sequence Diagram
- Conclusion & Next Steps β
1. Overview & Purpose
ViewCrews.cshtml is an ASP.NET Core Razor View responsible for displaying, searching, and managing Crews within the Field Log module. It provides:
- A search form to filter crews by name/creator.
- A Syncfusion EJ2 Grid to display crew records.
- Actions for creating, editing, and deleting crews.
- Smooth AJAX-based interactions for real-time updates without full page reloads.
2. Dependencies & Technologies
| Category | Details |
|---|---|
| Frontend Framework | ASP.NET Core Razor Views |
| CSS Libraries | Syncfusion EJ2 (material.css, fluent.css), Bootstrap 5 |
| JavaScript Library | Syncfusion EJ2 (ej2.min.js, ejs.interop.min.js), Fetch API |
| Server-Side Helpers | @Html.AntiForgeryToken(), Json.Serialize(...) |
| Layout | _TimeLayout.cshtml (Shared layout for time entry pages) |
| Modal Dialogs | Bootstrap 5 Modals |
3. Model & Data Structures
@model IEnumerable<IrbyImaging.UI.Models.CrewListItemViewModel>
CrewListItemViewModel (example):
| Property | Type | Description |
|---|---|---|
| CrewId | Guid |
Unique identifier of the crew |
| CrewName | string |
Name of the crew |
| CreatedBy | string |
User who created the crew |
| CreatedAt | DateTime |
Timestamp when created (optional) |
4. Layout & Razor Structure
@{
ViewData["Title"] = "View Crews";
Layout = "~/Views/Shared/_TimeLayout.cshtml";
}
<head> ... <!-- Syncfusion & CSS links --> </head>
<div class="container-fluid"> ... </div>
@Html.AntiForgeryToken()
<script> ... </script>
<style> ... </style>
- ViewData["Title"] sets the page title.
- Layout points to a shared layout for consistent look-and-feel.
- Syncfusion CSS/JS loaded via CDN for grid and controls.
- Inline scripts and styles handle UI logic and responsive design.
5. Key Functional Areas
5.1. Search Section
<div id="searchForm" class="row uniform-row">
<div class="col-md-4">
<label>Crew Name</label>
<ejs-textbox id="crewName" placeholder="Enter Crew Name"></ejs-textbox>
</div>
<div class="col-md-4">
<label>Created By</label>
<ejs-textbox id="createdBy" placeholder="Enter Creator Name"></ejs-textbox>
</div>
<div class="col-md-4 button-group">
<ejs-button id="searchBtn" content="Search" isPrimary="true"></ejs-button>
<ejs-button id="clearBtn" content="Clear"></ejs-button>
</div>
</div>
- TextBoxes (
ejs-textbox) for filtering by Crew Name and Created By. SearchandClearbuttons trigger AJAX filtering and reset.
5.2. Result Grid Section
<ejs-grid id="CrewGrid"
allowPaging="true"
allowSorting="true"
allowFiltering="true"
allowResizing="true"
allowExcelExport="true"
gridLines="Both"
height="450">
<e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
<e-grid-filterSettings type="Excel"></e-grid-filterSettings>
<e-grid-columns>
<e-grid-column field="CrewName" headerText="Crew Name" width="200"></e-grid-column>
<e-grid-column field="CreatedBy" headerText="Created By" width="200"></e-grid-column>
<e-grid-column headerText="Actions" template="#actionTemplate" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
- Paging, Sorting, Filtering, Resizing, Excel Export enabled.
- Three columns: Crew Name, Created By, and Actions.
5.3. Create New Crew
<ejs-button id="createBtn" content="Create New Crew" isPrimary="true"></ejs-button>
- On click, redirects to
/TimeEntry/CreateCrew.
5.4. Actions Template
<script id="actionTemplate" type="text/x-template">
<div class="action-buttons">
<a href="#" class="edit-link" data-id="${CrewId}">Edit</a>
<a href="#" class="delete-link" data-id="${CrewId}" data-name="${CrewName}">Delete</a>
</div>
</script>
- Edit: Opens
/TimeEntry/EditCrew/{CrewId}in a new tab. - Delete: Opens confirmation modal.
5.5. Delete Confirmation Modal
<div class="modal fade" id="deleteConfirmModal" ...>
<div class="modal-content">
<div class="modal-header">
<h5>Confirm Delete</h5>
<button class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
Are you sure you want to delete: <span id="crewToDelete"></span>?
</div>
<div class="modal-footer">
<button data-bs-dismiss="modal">Cancel</button>
<button id="confirmDeleteBtn" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
- Shows selected
<CrewName>and confirms deletion.
5.6. Anti-Forgery Token
@Html.AntiForgeryToken()
- Protects POST requests against CSRF attacks.
- Token is read in JavaScript and sent via
RequestVerificationTokenheader.
6. JavaScript Functionality
6.1. Initialization
document.addEventListener('DOMContentLoaded', function() {
const initialData = @Html.Raw(Json.Serialize(Model));
const gridInstance = document.getElementById('CrewGrid').ej2_instances[0];
gridInstance.dataSource = initialData;
gridInstance.refresh();
// Wire up buttons and links...
});
- Parses server-side model into JSON.
- Sets up grid, search, clear, create, edit, delete handlers.
6.2. Search & Clear Handlers
function performSearch() {
const params = new URLSearchParams({
crewName: getComponentValue('crewName'),
createdBy: getComponentValue('createdBy')
});
fetch(`/TimeEntry/ViewCrews?${params}`, { headers: {'X-Requested-With':'XMLHttpRequest'} })
.then(r => r.json())
.then(data => { gridInstance.dataSource = data; gridInstance.refresh(); })
.catch(err => alert('Search error'));
}
function clearForm() {
['crewName','createdBy'].forEach(id => getComponentInstance(id).value = null);
gridInstance.dataSource = initialData;
gridInstance.refresh();
}
- performSearch(): GETs filtered data as JSON and reloads grid.
- clearForm(): Resets inputs & restores initial grid data.
6.3. Create Crew Redirect
createBtnInstance.element.addEventListener('click', () => {
window.location.href = '/TimeEntry/CreateCrew';
});
- Redirects user to crew creation page.
6.4. Edit Crew
document.body.addEventListener('click', e => {
if (e.target.classList.contains('edit-link')) {
e.preventDefault();
window.open(`/TimeEntry/EditCrew/${e.target.dataset.id}`, '_blank');
}
});
- Opens the Edit Crew form in a new tab/window.
6.5. Delete Crew Workflow
function deleteCrew(id, name) {
crewIdToDelete = id;
document.getElementById('crewToDelete').textContent = name;
new bootstrap.Modal('#deleteConfirmModal').show();
}
confirmDeleteBtn.addEventListener('click', () => {
fetch('/TimeEntry/DeleteCrew', {
method: 'POST',
headers: {
'Content-Type':'application/json',
'RequestVerificationToken': token
},
body: JSON.stringify({ crewId: crewIdToDelete })
})
.then(r => r.json())
.then(data => {
if (data.success) {
// Remove row from grid
gridInstance.dataSource = gridInstance.dataSource.filter(c => c.CrewId !== crewIdToDelete);
gridInstance.refresh();
alert('Crew deleted successfully.');
} else {
alert(data.message || 'Delete failed.');
}
})
.catch(() => alert('An error occurred.'))
.finally(() => crewIdToDelete = null);
});
- deleteCrew(): Prepares and shows confirmation modal.
- confirmDeleteBtn: Sends AJAX POST, updates grid on success.
7. Styling & Responsive Design π¨
- Custom CSS to match corporate branding (
#11467eprimary color). - Overrides Syncfusion grid styling for precise column widths, ellipses, alternate rows.
- Media queries ensure usability on tablets and phones (column percentages, padding adjustments).
8. API Endpoints Overview π
| Endpoint | Method | Description | Request | Response |
|---|---|---|---|---|
/TimeEntry/ViewCrews |
GET | Filters crews by query params, returns JSON | ?crewName=&createdBy= |
List<CrewListItem> |
/TimeEntry/DeleteCrew |
POST | Deletes a crew by ID, requires CSRF token | { crewId: "..." }, header token |
{ success: bool, message?: string } |
/TimeEntry/CreateCrew |
GET/POST | Renders or submits new crew form | β | HTML / JSON response |
/TimeEntry/EditCrew/{id} |
GET/POST | Renders or updates existing crew form | β | HTML / JSON response |
9. Sample Code Blocks
Razor Model Declaration
@model IEnumerable<IrbyImaging.UI.Models.CrewListItemViewModel>
Grid Column Definition
<e-grid-column field="CrewName" headerText="Crew Name" width="200"></e-grid-column>
<e-grid-column field="CreatedBy" headerText="Created By" width="200"></e-grid-column>
<e-grid-column headerText="Actions" template="#actionTemplate" width="150"></e-grid-column>
AJAX Delete Request
fetch('/TimeEntry/DeleteCrew', {
method: 'POST',
headers: {
'Content-Type':'application/json',
'RequestVerificationToken': token
},
body: JSON.stringify({ crewId: crewIdToDelete })
})
10. Usage Flow Example
- Load Page: Grid populates with all crews.
- Search: Enter criteria β click Search β grid filters results.
- Clear: Click Clear β inputs reset β grid restores all data.
- Create: Click Create New Crew β navigates to creation form.
- Edit: Click Edit on a row β opens edit form in new tab.
- Delete: Click Delete β confirm modal β deletion via AJAX β grid refresh.
11. UML Sequence Diagram
sequenceDiagram
participant U as User
participant B as Browser/JS
participant S as Server
participant G as Syncfusion Grid
U->>B: Click "Delete" link
B->>B: Show confirmation modal
U->>B: Click "Delete" in modal
B->>S: POST /TimeEntry/DeleteCrew { crewId }
S-->>B: { success: true }
B->>G: Remove row & refresh
B->>U: Alert "Crew deleted successfully."
12. Conclusion & Next Steps β
This documentation covers the ViewCrews.cshtml view in detail. You now understand:
- How the Razor view is structured.
- Integration with Syncfusion EJ2 components.
- AJAX workflows for search, create, edit, and delete.
- Responsive styling and corporate theming.
Next Steps:
- Implement server-side methods (
ViewCrews,DeleteCrew). - Ensure anti-forgery token validation on POST.
- Expand error handling and user-friendly notifications (toasts).
- Add unit/integration tests for AJAX endpoints.
π Youβre now ready to maintain and extend the βView Crewsβ feature!