Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

How to show validation message while user give invalid data or wrong URL?

$
0
0

Hi Panel;

I have created a web API method called as GETStudedntDetails and I am returning value by JSON.

Bellow is my method;

public HttpResponseMessage Get(string id,string name)
{
string errormessage=""
if(id==null)
{
errormessage="ENter ID";
flag=true
}
if(name==null)
{
errormessage="ENter name";
flag=true;
}
if(flag)
{
return content=new httpResponsemessage{
errormesage=errormessage
}
}


}

In the above code I am checking with null value and if condtion satisfy I am returning error message .

But in JSON format the out put coming like this;

"ErrorMessage" : "Enter StudentName. Enter StudentRoll".

Is it possible to place each error separate line; and is it correct approach to do this ?

Thanks;

SK.


Viewing all articles
Browse latest Browse all 4850

Trending Articles