📝 Documentation: _IndexPartial.cshtml
Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Models & Data Models
- Code Walkthrough
- UML Class Diagram
- Usage Example
- Common Scenarios & Tips
- Conclusion
1. Overview & Purpose
This Razor partial view (_IndexPartial.cshtml) is part of the HRImaging feature in the IrbyImaging ASP.NET Core MVC application.
Primary goal
- Dynamically render a list of document attributes for indexing HR-related images.
- For each attribute, it outputs hidden form fields (to persist metadata) and, if applicable, a dropdown to select among multiple values.
When is it used?
- Included in a parent view (e.g.,
Index.cshtml) to collect or display metadata on a scanned document. - Works with the
DocumentAttributeViewDetailview model to generate UI elements based on each attribute’s configuration.
2. Key Functional Areas
| Area | Description |
|---|---|
| 🔒 Hidden Inputs | Persists metadata (ID, name, type, flags) for each document attribute in hidden form fields. |
| 🔽 Multi-Value Dropdown | Renders a <select> element when an attribute supports multiple values, using asp-items. |
| 🔄 Loop & Tag Helpers | Iterates over the model list; uses Razor Tag Helpers (asp-for, asp-items) for binding. |
3. Dependencies & Technologies
- ASP.NET Core 6.0+ Razor Pages / MVC
- Tag Helpers:
asp-forfor strongly-typed binding.asp-itemsto bind aSelectListfor dropdown options.
- Model:
List<IrbyImaging.UI.Models.DocumentAttributeViewDetail>
4. View Models & Data Models
DocumentAttributeViewDetail
| Property | Type | Description |
|---|---|---|
Id |
int |
Unique identifier of the attribute. |
AttributeName |
string |
Display name / key for the attribute. |
IndexValue |
string |
Currently selected or default value. |
IsMultiValue |
bool |
Flag indicating if multiple values are available. |
AttributeType |
string |
Data type (e.g., Text, Date, Number). |
IsRequired |
bool |
Whether this attribute is mandatory. |
LinkEmployeeData |
bool |
If true, links to employee data for default values. |
LinkJobData |
bool |
If true, links to job-related data. |
LinkCustomerData |
bool |
If true, links to customer-related data. |
MultiValueTypes |
SelectList |
Collection of options when IsMultiValue = true. |
5. Code Walkthrough
@model List<IrbyImaging.UI.Models.DocumentAttributeViewDetail>
@for (var i = 0; i < Model.Count; i++)
{
<!-- Hidden inputs to persist metadata on postback -->
<input type="hidden" asp-for="@Model[i].Id" />
<input type="hidden" asp-for="@Model[i].AttributeName" />
<input type="hidden" asp-for="@Model[i].IndexValue" />
<input type="hidden" asp-for="@Model[i].IsMultiValue" />
<input type="hidden" asp-for="@Model[i].AttributeType" />
<input type="hidden" asp-for="@Model[i].IsRequired" />
<input type="hidden" asp-for="@Model[i].LinkEmployeeData" />
<input type="hidden" asp-for="@Model[i].LinkJobData" />
<input type="hidden" asp-for="@Model[i].LinkCustomerData" />
@* If the attribute supports multiple values, render a dropdown *@
if (Model[i].IsMultiValue)
{
<div class="row mb-4">
<label for="@Model[i].AttributeName" class="col-form-label col-lg-3">
@Model[i].AttributeName
</label>
<div class="col-lg-9">
<select name="IndexValue"
id="@Model[i].AttributeName"
class="form-control col-sm-6"
asp-items="@Model[i].MultiValueTypes">
<option value="None Selected"
selected
disabled
hidden>
Select @Model[i].AttributeName Value
</option>
</select>
</div>
</div>
}
}
5.1. Hidden Inputs Section
- Purpose: All properties of each attribute are emitted as hidden inputs.
- Why? Maintaining state on postback—ensures the controller receives the full metadata for processing.
5.2. Multi-Value Dropdown Section
- Rendered when:
IsMultiValue == true. - Components:
<label>: Tied to the dropdown viaforattribute.<select>with:asp-items: Binds aSelectListof options.- A default
<option>prompting the user.
6. UML Class Diagram
classDiagram
class DocumentAttributeViewDetail {
+int Id
+string AttributeName
+string IndexValue
+bool IsMultiValue
+string AttributeType
+bool IsRequired
+bool LinkEmployeeData
+bool LinkJobData
+bool LinkCustomerData
+SelectList MultiValueTypes
}
7. Usage Example
Controller Action
public IActionResult Index()
{
var attributes = _attributeService.GetDocumentAttributes();
// returns List<DocumentAttributeViewDetail> with MultiValueTypes populated
return View(attributes);
}
Parent View (Index.cshtml)
@model List<DocumentAttributeViewDetail>
<form asp-action="Index" method="post">
<!-- Include the partial that renders attribute inputs -->
@Html.Partial("_IndexPartial", Model)
<button type="submit" class="btn btn-primary">
Submit 📤
</button>
</form>
8. Common Scenarios & Tips
- Validation:
- Since most inputs are hidden, ensure server-side validation covers required fields.
- Use ModelState checks in the POST action.
- Styling:
- Customize the
row mb-4or column classes to match your UI theme.
- Customize the
- Extensibility:
- To handle single-value attributes (e.g., text input), extend the
ifblock to include<input type="text" />. - Use
asp-for="@Model[i].IndexValue"for two-way binding on text fields.
- To handle single-value attributes (e.g., text input), extend the
9. Conclusion
This partial view abstracts the rendering of document attribute metadata into a clean, reusable component. By looping over a strongly-typed list and leveraging ASP.NET Core Tag Helpers, it:
- Ensures hidden fields carry over all necessary metadata
- Dynamically produces dropdowns for attributes that offer multiple options
- Keeps the parent view uncluttered and focused on layout and overall form logic
Feel free to extend it for single-value attributes, custom client‐side scripts, or richer UI components! 🎉