As Bruce said, "The model is not null, just all the properties are.". If you want to judge, you need to customize a method to judge all attributes.Just like this:
The method:
public bool IsAnyNullOrEmpty(object myObject)
{
foreach (PropertyInfo pi in myObject.GetType().GetProperties())
{
if (pi.PropertyType == typeof(string))
{
string value = (string)pi.GetValue(myObject);
if (!string.IsNullOrEmpty(value))
{
return false;
}
}
}
return true;
}
How to call it:
if (IsAnyNullOrEmpty(taskgetmodel))
{
return new Response("Please supply inputs", HttpStatusCode.BadRequest);
}
None
0 Points
18 Posts
Doesn't hit null value
Oct 15, 2019 07:28 AM|SinjuRenny|LINK
When i pass the body of a postman as { } only and check the controller(here i used taskgetmodel to pass parameters)
if( taskgetmodel)==null
{
return new Response("Please supply inputs", HttpStatusCode.BadRequest);
}
but it doesnot hit the above condition.
All-Star
57874 Points
15507 Posts
Re: Doesn't hit null value
Oct 15, 2019 10:02 AM|bruce (sqlwork.com)|LINK
Member
170 Points
88 Posts
Re: Doesn't hit null value
Oct 16, 2019 03:22 AM|Lewis Lu|LINK
Hi SinjuRenny,
As Bruce said, "The model is not null, just all the properties are.". If you want to judge, you need to customize a method to judge all attributes.Just like this:
The method:
How to call it:
Best Regards,
Lewis
None
0 Points
18 Posts
Re: Doesn't hit null value
Oct 16, 2019 03:37 AM|SinjuRenny|LINK
Thanks it work..