TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sujeet Raman
857
927
352.1k
how to validate model in asp.net core 3.1 web api post method?
Mar 26 2021 7:11 AM
Hi
I have an api post method. I don't have any UI to use that api so i need to show my error message in postman. If I miss one property the missing property error message should be displayed in postman.i confused with many post in internet.
my post method
[HttpPost(
"api/Student/Check"
)]
public
async Task Check([FromBody] students input)
{
var result = await _students.studentAsync(input);
return
Ok(result);
}
my model
public
class
students
{
[JsonProperty(
"studentid"
)]
public
int
studentid{
get
;
set
; }
[JsonProperty(
"studentname"
)]
public
int
studentname{
get
;
set
; }
[JsonProperty(
"studentage"
)]
public
int
studentage{
get
;
set
; }
}
}
I should get like:
Expected Result: Status code is 400 bad request and response should be as below:
student id is required.This cannot be null or blank.
student name is required.This cannot be null or blank
student age field is required.This cannot be null or blank.
Reply
Answers (
5
)
Export a PDF Using Existing HTML URL Using Asp.Net MVC
Ajax not hitting controller