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
L A
NA
170
170.9k
Can't return a type of IHttpActionResult - WebAPI
Jun 28 2017 1:38 AM
Hello all,
Firstly, this question is about WebAPI. But as i didnt found WebAPI under
Category
Dropdown, i posted under
.NET General
.
I'm working on MVC WebAPI, where WebAPI Performs a GET operation. But i'm unable to return type of IHttpActionResult.
Below is my
WebAPI
GET Action method.
public
IHttpActionResult GetDataFromDB()
{
try
{
using
(var ctx =
new
AdventureWorks2012Entities())
{
var query = (from d
in
ctx.Departments
join h
in
ctx.EmployeeDepartmentHistories
on d.DepartmentID equals h.DepartmentID
join s
in
ctx.Shifts on h.ShiftID equals s.ShiftID
join e
in
ctx.Employees
on h.BusinessEntityID equals e.BusinessEntityID
join p
in
ctx.People
on h.BusinessEntityID equals p.BusinessEntityID
select
new
{
Name = ((p.FirstName ==
null
?
""
: p.FirstName) +
" "
+
(p.MiddleName ==
null
?
""
: p.MiddleName) +
" "
+
(p.LastName ==
null
?
""
: p.LastName)),
MaritalStatus = (e.MaritalStatus ==
"M"
?
"Married"
:
"Single"
),
Gender = (e.Gender ==
"M"
?
"Male"
:
"FeMale"
),
Designation = e.JobTitle,
Department = d.Name,
MajorBranch = d.GroupName
}).ToList();
if
(query.Count == 0)
{
return
NotFound();
}
return
Ok(query);
}
}
catch
(Exception) {
return
null
; }
finally
{
}
}
Above code is working fine when i debug & Line # 29 show data in List format. But on browser it displaying as Error.
I can view output on Fiddler.
Please suggest me to figure out my mistake & achieve this.
Thanks in advance.
Reply
Answers (
3
)
Planning to take up classes on MVC, WCF and WPF in Chennai
How to close Telerik Menu Sub items in mouse leave event c#