Click here to Skip to main content
15,896,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list like this below:
[
{
"hospital_Name": "Abbey View Medical Centre"
},
{
"hospital_Name": "Abingdon Mental Health Centre"
},
{
"hospital_Name": "Accrington Victoria Community Hospital"
}
]

but i need to give an object name of this array list,but it is not coming..

What I have tried:

I am giving the code below

Controller Code:
[Route("fetchNHSHospitalsRecords"), HttpGet]
public IHttpActionResult NHSHospitalsRecords()
{
try
{
var result = db.FetchNHSHospitalsRecords().Select(h => h.Hospital_Name).ToArray();
// var result = db.FetchNHSHospitalsRecords();
return Ok(result);

}
catch (Exception e)
{
return InternalServerError(e);
}
}

Function Return Code:

public List<nhshospitals> FetchNHSHospitalsRecords()
{
using (var con = GetDbConnection())
{
string query = "select distinct Hospital_Name from NHSHospitals WHERE Hospital_Name IS NOT NULL Order By Hospital_Name"; List<nhshospitals> objlstcstr = con.RunQuery<nhshospitals>(query);
return con.RunQuery<nhshospitals>(query);
}
}

Plz Help..
Posted
Updated 15-Nov-19 1:12am

1 solution

return Ok(new { hospitals = result });
 
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