Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
how can i check validaion on data dictionary attributes for example check if Firstname and last name is not null or length>0 using Model Validation in ASP.NET Web API

C#
public HttpResponseMessage Post([FromBody] List<Dictionary<string,string>> _lstDicobject)
      {
//JsonConvert.DeserializeObject<Person>(JsonConvert.SerializeObject(kvpList)) object (person) data type
return JsonConvert.DeserializeObject<Person>(JsonConvert.SerializeObject(kvpList)).sendMail();
     }

where person class

C#
class person {
public string Firstname {set ; get;}
public string lastname {set ; get;}
public string send mail()
{
return Firstname+" "+ lastname;
}
}
Posted

1 solution

Refer - Model Validation in ASP.NET Web API[^].
C#
if (ModelState.IsValid)
This is what you can do.

On Model Class, declare your variable with proper attributes. Like for not null, you can mark it with [Required] attribute.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900