MvcUtils Class
Provides utility methods for common MVC operations, including controller and action naming conventions, parameter validation, and model state error handling.
public static class MvcUtilsInheritance System.Object → MvcUtils
Methods
MvcUtils.NameOf<TController>() Method
Retrieves the name of a controller type, removing the 'Controller' suffix.
public static string NameOf<TController>()
where TController : Microsoft.AspNetCore.Mvc.ControllerBase;Type parameters
TController
The type of the controller.
Returns
System.String
The name of the controller stripped of the 'Controller' suffix.
Exceptions
System.InvalidOperationException
Thrown if the controller's name does not follow the expected
naming convention.
Remarks
This method is useful for generating controller names dynamically, such as when building URLs or referencing controllers in logs.
MvcUtils.Required<T>(this T, string) Method
Validates that an object is not null and satisfies the Abblix.Oidc.Server.Mvc.MvcUtils.RequiredAttribute validation, emulating model validation in ASP.NET MVC.
public static T Required<T>(this T? value, string name)
where T : class;Type parameters
T
The type of the object being validated.
Parameters
value T
The object to validate.
name System.String
The name of the parameter, used for error message formatting.
Returns
T
The validated, non-null object.
Exceptions
System.InvalidOperationException
Thrown if the object is null or does not satisfy
the required validation.
Remarks
This method provides a programmatic way to enforce non-nullability and validation of method parameters, mimicking data annotations used in model classes.
MvcUtils.TrimAsync(string) Method
Removes the 'Async' suffix from the name of an asynchronous action method.
public static string TrimAsync(string action);Parameters
action System.String
The name of the action method.
Returns
System.String
The action name without the 'Async' suffix.
Exceptions
System.InvalidOperationException
Thrown if the action's name does not end with 'Async' as per
the naming convention.
Remarks
This method assists in referencing action methods by their logical names without the asynchronous operation indicator.