ErrorViewModel
TheErrorViewModel is used to pass error information to the error view page.
Namespace: dev_showcase.Models
Properties
RequestId
A unique identifier for the current request. Nullable string type.
RequestId is set to either:
Activity.Current?.Id- The current activity’s trace ID if availableHttpContext.TraceIdentifier- The HTTP context trace identifier as a fallback
ShowRequestId
A computed property that returns
true if RequestId is not null or empty.Usage in Error Handling
TheErrorViewModel is instantiated in the HomeController.Error() action method:
Purpose
This model serves two main purposes:- Error Tracking: Provides a unique identifier to track and debug specific error instances
- User Display: Allows the error view to conditionally show diagnostic information based on whether a request ID is available