ASP.NET Core MVC Interview Question #138
What is the purpose of the MVC ErrorViewModel pattern?
Dependency Injection, Services, Error Handling, Logging & Performance Senior Advanced
Quick Interview Answer
An error ViewModel supplies safe information needed by a user-facing error page, commonly a request or correlation identifier. It should not expose the raw exception or sensitive internal details to the browser.
Detailed Explanation
An error ViewModel supplies safe information needed by a user-facing error page, commonly a request or correlation identifier. It should not expose the raw exception or sensitive internal details to the browser.
Detailed exception information belongs in protected server-side logs or observability systems, while the public error page should provide a stable and safe user experience.
Code Example
public class ErrorViewModel
{
public string? RequestId { get; set; }
public bool ShowRequestId =>
!string.IsNullOrEmpty(RequestId);
}