Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Can't return a type of IHttpActionResult - WebAPI
Learn Avid
Jun 28 2017 1:38 AM
218
Reply
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.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Planning to take up classes on MVC, WCF and WPF in Chennai
How to make my combobox autocomplete with multiple columns