mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Add example of server and client validation for React
This commit is contained in:
30
samples/react/ReactGrid/Controllers/PeopleApiController.cs
Normal file
30
samples/react/ReactGrid/Controllers/PeopleApiController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace ReactExample.Controllers
|
||||
{
|
||||
public class PeopleApiController : Controller
|
||||
{
|
||||
[HttpPut("api/people/{personId:int}")]
|
||||
public async Task<ActionResult> UpdatePerson([FromBody] PersonDto person)
|
||||
{
|
||||
if (!ModelState.IsValid) {
|
||||
return HttpBadRequest(ModelState);
|
||||
} else {
|
||||
return new HttpOkResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PersonDto {
|
||||
public string name { get; set; }
|
||||
public string city { get; set; }
|
||||
public string state { get; set; }
|
||||
public string country { get; set; }
|
||||
public string company { get; set; }
|
||||
|
||||
[Range(1, 10)]
|
||||
public int favoriteNumber { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user