Skip to content

Instantly share code, notes, and snippets.

@markvincze
Created February 11, 2017 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markvincze/9963630ac0d916ff29f86a71b4aa1877 to your computer and use it in GitHub Desktop.
Save markvincze/9963630ac0d916ff29f86a71b4aa1877 to your computer and use it in GitHub Desktop.
Trying to reproduce NRE with ValidateActionParametersAttribute
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