Knight.Response.Mvc
1.0.0
See the version list below for details.
dotnet add package Knight.Response.Mvc --version 1.0.0
NuGet\Install-Package Knight.Response.Mvc -Version 1.0.0
<PackageReference Include="Knight.Response.Mvc" Version="1.0.0" />
<PackageVersion Include="Knight.Response.Mvc" Version="1.0.0" />
<PackageReference Include="Knight.Response.Mvc" />
paket add Knight.Response.Mvc --version 1.0.0
#r "nuget: Knight.Response.Mvc, 1.0.0"
#:package Knight.Response.Mvc@1.0.0
#addin nuget:?package=Knight.Response.Mvc&version=1.0.0
#tool nuget:?package=Knight.Response.Mvc&version=1.0.0
Knight.Response.Mvc
Knight.Response.Mvc
provides integration between Knight.Response and ASP.NET MVC / Web API 2 (System.Web on .NET Framework 4.7.1+).
It brings consistent API response handling, including ProblemDetails
compatibility and factory methods for building standardized responses.
This package is the MVC counterpart to Knight.Response.AspNetCore
, designed for projects that cannot use ASP.NET Core but still want the same structured response model.
Features
- Extension Methods
ResultExtensions
→ ConvertsResult
/Result<T>
intoIActionResult
ServiceCollectionExtensions
→ Registers Knight.Response services for MVC
- Factories
ApiResults
→ Strongly-typed helpers to return success, failure, unauthorized, forbidden, etc.ProblemFactory
→ Builds RFC 7807-compatibleProblemDetails
for error responses
- Infrastructure
CompatProblemDetails
→ CompatibleProblemDetails
implementation for MVC / Web API 2CompatValidationProblemDetails
→ Validation error details aligned with modern ASP.NET Core behavior
- Options
KnightResponseOptions
→ Configurable options for customizing error shape, problem details, etc.
Installation
dotnet add package Knight.Response.Mvc
This package depends on:
Knight.Response
(core results)Knight.Response.Abstractions.Http
(shared options + mapper)Microsoft.AspNetCore.Mvc
(2.x)
Usage
1. Configure Services
Register Knight.Response in Startup.cs
:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var services = new ServiceCollection();
services.AddKnightResponse(); // from ServiceCollectionExtensions
}
}
2. Return Results in Controllers
public class AccountsController : ApiController
{
[HttpGet]
public IHttpActionResult GetAccount(string id)
{
var result = _accountService.GetById(id);
// Convert Result<T> → IActionResult
return result.ToOkActionResult();
}
[HttpPost]
public IHttpActionResult Create(CreateAccountRequest request)
{
var result = _accountService.Create(request);
// Returns standardized 201 Created or BadRequest/ProblemDetails as per configuration
return result.ToCreatedActionResult();
}
}
Success payload shape
Controlled by KnightResponseOptions.IncludeFullResultPayload
:
- true (default): return the full
Result
object on success (useful for clients that want messages even on success). - false:
- Ok → returns
Value
(ofResult<T>
) only - Created / Accepted →
Value
only
- Ok → returns
Failure mapping
- If
UseValidationProblemDetails
is true and the mapper produces fields errors, the response is a ValidationProblemDetails. - Otherwise, a standard ProblemDetails is returned.
- Status code is resolved from
Result.Status
usingStatusCodeResolver
(defaults:Failed
= 400,Cancelled
= 409,Error
= 500,Completed
not used)
Options
Options type comes from
public sealed class KnightResponseOptions
: KnightResponseBaseOptions<ProblemDetails, ValidationProblemDetails>
{
// Same core properties:
// - IncludeFullResultPayload
// - UseProblemDetails
// - UseValidationProblemDetails
// - IncludeExceptionDetails
// - StatusCodeResolver
// - ValidationMapper (default: DefaultValidationErrorMapper from Abstractions)
// - ProblemDetailsBuilder, ValidationBuilder
}
Register and customize:
builder.Services.AddKnightResponse(options =>
{
options.IncludeFullResultPayload = true;
options.UseProblemDetails = true;
options.UseValidationProblemDetails = true;
options.StatusCodeResolver = status => status switch
{
Status.Failed => StatusCodes.Status400BadRequest,
Status.Cancelled => StatusCodes.Status409Conflict,
Status.Error => StatusCodes.Status500InternalServerError,
_ => StatusCodes.Status400BadRequest
};
});
Related Packages
- Knight.Response — Core response model
- Knight.Response.Abstractions.Http — Shared HTTP abstractions (ProblemDetails, validation mapping)
- Knight.Response.AspNetCore — ASP.NET Core integration
Which package do I use?
- Use Knight.Response.Mvc → For System.Web MVC / Web API 2 apps targeting .NET Framework.
- Use Knight.Response.AspNetCore → For ASP.NET Core apps targeting .NET 6/7/8+.
Note:
Knight.Response.Mvc
may referenceMicrosoft.AspNetCore.Mvc
types (likeProblemDetails
) purely for compatibility. This does not require ASP.NET Core runtime.
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Knight.Response.Abstractions.Http (>= 1.0.2)
- Microsoft.AspNetCore.Mvc (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.0.0-preview04 | 92 | 9/27/2025 |
2.0.0-preview03 | 175 | 9/25/2025 |
2.0.0-preview02 | 172 | 9/24/2025 |
2.0.0-preview01 | 231 | 9/24/2025 |
1.0.0 | 145 | 9/14/2025 |
0.1.0 | 153 | 9/14/2025 |
Changed:
- Promoted from preview (0.1.0) to stable (1.0.0).
- No breaking changes; API surface is unchanged.
- Documentation updated to clarify supported frameworks and related packages.
Features:
- Convert `Result` / `Result<T>` to `IActionResult` via `ResultExtensions`.
- `ApiResults` factory for consistent HTTP responses (200, 201, 202, 204, 400, 404, 409).
- `ProblemFactory` for building RFC 7807-style error objects.
- `CompatProblemDetails` and `CompatValidationProblemDetails` for MVC compatibility.
- Configurable via `KnightResponseOptions`.
- Fully unit tested and mutation tested for reliability.