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
Edward Mahoney
NA
10
5.1k
Return from ASP.NET Core Web API a dictionary, not List
Mar 11 2021 12:00 AM
I found your article below excellent. Great job.
https://www.c-sharpcorner.com/article/apiasp-net-core-web-api-entity-framewor-call-stored-procedure-part-ii/
My question is how do I get a non list JSON response returned. The person consuming the json wants a dictionary, not a list. My stored proc returns one row so no list is needed.
So from your example I want
{
"appointmentId"
: 2,
"returnCode"
: 1,
"submittedTime"
:
"2020-12-06T15:19:10.87"
}
not this:
[
{
"appointmentId"
: 2,
"returnCode"
: 1,
"submittedTime"
:
"2020-12-06T15:19:10.87"
}
]
public
async Task<ActionResult<IEnumerable<output>>> Getoutput(Input input)
{
string
StoredProc =
"exec CreateAppointment "
+
"@ClinicID = "
+ input.ClinicId +
","
+
"@AppointmentDate = '"
+ input.AppointmentDate +
"',"
+
"@FirstName= '"
+ input.FirstName +
"',"
+
"@LastName= '"
+ input.LastName +
"',"
+
"@PatientID= "
+ input.PatientId +
","
+
"@AppointmentStartTime= '"
+ input.AppointmentStartTime +
"',"
+
"@AppointmentEndTime= '"
+ input.AppointmentEndTime +
"'"
;
//return await _context.output.ToListAsync();
return
await _context.output.FromSqlRaw(StoredProc).ToListAsync();
}
Reply
Answers (
4
)
Table with a DropDownListFor inside every row in a Partial View .NET
Item deletion from list on client side