parent
6b2a702ff4
commit
0bb3f18049
|
|
@ -1750,7 +1750,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="BadRequestObjectResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
/// Creates an <see cref="BadRequestObjectResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="modelState">The model state dictionary containing errors to be returned to the client.</param>
|
/// <param name="modelState">The <see cref="ModelStateDictionary" /> containing errors to be returned to the client.</param>
|
||||||
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
|
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState)
|
public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState)
|
||||||
|
|
@ -1787,7 +1787,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.
|
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="modelState">The model state dictionary containing errors to be returned to the client.</param>
|
/// <param name="modelState">The <see cref="ModelStateDictionary" /> containing errors to be returned to the client.</param>
|
||||||
/// <returns>The created <see cref="UnprocessableEntityObjectResult"/> for the response.</returns>
|
/// <returns>The created <see cref="UnprocessableEntityObjectResult"/> for the response.</returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual UnprocessableEntityObjectResult UnprocessableEntity(ModelStateDictionary modelState)
|
public virtual UnprocessableEntityObjectResult UnprocessableEntity(ModelStateDictionary modelState)
|
||||||
|
|
@ -1820,7 +1820,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="ConflictObjectResult"/> that produces a <see cref="StatusCodes.Status409Conflict"/> response.
|
/// Creates an <see cref="ConflictObjectResult"/> that produces a <see cref="StatusCodes.Status409Conflict"/> response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="modelState">The model state dictionary containing errors to be returned to the client.</param>
|
/// <param name="modelState">The <see cref="ModelStateDictionary" /> containing errors to be returned to the client.</param>
|
||||||
/// <returns>The created <see cref="ConflictObjectResult"/> for the response.</returns>
|
/// <returns>The created <see cref="ConflictObjectResult"/> for the response.</returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual ConflictObjectResult Conflict(ModelStateDictionary modelState)
|
public virtual ConflictObjectResult Conflict(ModelStateDictionary modelState)
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,39 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="BadRequestResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The created <see cref="BadRequestResult"/> for the response.</returns>
|
||||||
|
[NonAction]
|
||||||
|
public virtual BadRequestResult BadRequest()
|
||||||
|
=> new BadRequestResult();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="BadRequestObjectResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="error">An error object to be returned to the client.</param>
|
||||||
|
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
|
||||||
|
[NonAction]
|
||||||
|
public virtual BadRequestObjectResult BadRequest(object error)
|
||||||
|
=> new BadRequestObjectResult(error);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="BadRequestObjectResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="modelState">The <see cref="ModelStateDictionary" /> containing errors to be returned to the client.</param>
|
||||||
|
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
|
||||||
|
[NonAction]
|
||||||
|
public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState)
|
||||||
|
{
|
||||||
|
if (modelState == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(modelState));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BadRequestObjectResult(modelState);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="ChallengeResult"/>.
|
/// Creates a <see cref="ChallengeResult"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -520,6 +520,39 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
propertyFilter);
|
propertyFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="BadRequestResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The created <see cref="BadRequestResult"/> for the response.</returns>
|
||||||
|
[NonAction]
|
||||||
|
public virtual BadRequestResult BadRequest()
|
||||||
|
=> new BadRequestResult();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="BadRequestObjectResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="error">An error object to be returned to the client.</param>
|
||||||
|
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
|
||||||
|
[NonAction]
|
||||||
|
public virtual BadRequestObjectResult BadRequest(object error)
|
||||||
|
=> new BadRequestObjectResult(error);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="BadRequestObjectResult"/> that produces a <see cref="StatusCodes.Status400BadRequest"/> response.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="modelState">The <see cref="ModelStateDictionary" /> containing errors to be returned to the client.</param>
|
||||||
|
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
|
||||||
|
[NonAction]
|
||||||
|
public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState)
|
||||||
|
{
|
||||||
|
if (modelState == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(modelState));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BadRequestObjectResult(modelState);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="ChallengeResult"/>.
|
/// Creates a <see cref="ChallengeResult"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,20 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PageHandlerCanReturnBadRequest()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Pages/HandlerWithParameter");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var response = await Client.SendAsync(request);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
|
Assert.Equal("Parameter cannot be null.", await response.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HelloWorld_CanGetContent()
|
public async Task HelloWorld_CanGetContent()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1495,6 +1495,35 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);
|
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BadRequest_SetsStatusCode()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var page = new TestPage();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = page.BadRequest();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<BadRequestResult>(result);
|
||||||
|
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BadRequest_SetsStatusCodeAndResponseContent()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var page = new TestPage();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = page.BadRequest("Test Content");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<BadRequestObjectResult>(result);
|
||||||
|
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
|
||||||
|
Assert.Equal("Test Content", result.Value);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NotFound_SetsStatusCode()
|
public void NotFound_SetsStatusCode()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1486,6 +1486,35 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);
|
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BadRequest_SetsStatusCode()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var page = new TestPage();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = page.BadRequest();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<BadRequestResult>(result);
|
||||||
|
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BadRequest_SetsStatusCodeAndResponseContent()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var page = new TestPage();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = page.BadRequest("Test Content");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<BadRequestObjectResult>(result);
|
||||||
|
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
|
||||||
|
Assert.Equal("Test Content", result.Value);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NotFound_SetsStatusCode()
|
public void NotFound_SetsStatusCode()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
|
||||||
|
|
||||||
namespace RazorPagesWebSite
|
namespace RazorPagesWebSite
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
namespace RazorPagesWebSite
|
namespace RazorPagesWebSite
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
@page
|
||||||
|
@model HandlerWithParameterModel
|
||||||
|
@{
|
||||||
|
}
|
||||||
|
Handler with parameter
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace RazorPagesWebSite.Pages
|
||||||
|
{
|
||||||
|
public class HandlerWithParameterModel : PageModel
|
||||||
|
{
|
||||||
|
public IActionResult OnGet(string testParameter = null)
|
||||||
|
{
|
||||||
|
if (testParameter == null)
|
||||||
|
{
|
||||||
|
return BadRequest("Parameter cannot be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue