Created
February 11, 2017 10:59
-
-
Save markvincze/9963630ac0d916ff29f86a71b4aa1877 to your computer and use it in GitHub Desktop.
Trying to reproduce NRE with ValidateActionParametersAttribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
using Microsoft.AspNetCore.Mvc; | |
using System.Linq; | |
namespace WebApplication.Controllers | |
{ | |
public class Person | |
{ | |
public string Name { get; set; } | |
} | |
[RouteAttribute("[controller]")] | |
public class PeopleController : Controller | |
{ | |
[HttpPost] | |
[ValidateActionParameters] | |
public IActionResult Post([FromBody][Required]Person person) | |
{ | |
if(!ModelState.IsValid) | |
{ | |
return StatusCode(400, ModelState.First().Value); | |
} | |
if(person != null) | |
return Ok(person.Name); | |
else | |
return Ok("person was null"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment