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
Ramco Ramco
441
3.4k
522.6k
httpStatusCode:not found when trying to Delete
Feb 24 2021 7:13 AM
Hi
Trying to delete record but it is giving above error. Get is working o.k
public
class
EmployeesController: ApiController {
private
PMDbEntities db =
new
PMDbEntities();
// GET: api/Employees
public
IHttpActionResult GetEmployees() {
try
{
var results = (from d
in
db.Employees join f
in
db.Departments on d.DepartmentId equals f.ID select
new
{
Id = d.ID, Name = d.Name, Department = f.Description
}).ToList();
if
(results ==
null
) {
return
NotFound();
}
return
Ok(results);
}
catch
(Exception) {
return
BadRequest();
}
}
// DELETE: api/Employees/5
[ResponseType(
typeof
(Employee))]
public
IHttpActionResult DeleteEmployee(
int
id) {
try
{
Employee employee = db.Employees.Find(id);
if
(employee ==
null
) {
return
Content(HttpStatusCode.NotFound,
"Employee not found"
);
}
else
{
db.Employees.Remove(employee);
db.SaveChanges();
return
Ok(employee);
}
}
catch
(Exception ex) {
return
BadRequest(
"Error Encountered : "
+ ex);
}
}
}
protected
void
btnDelete_Click(
object
sender, EventArgs e) {
RestClient restClient =
new
RestClient(
"http://localhost:40991/api/Employees/"
);
restClient.Timeout = -1;
RestRequest request =
new
RestRequest(Method.DELETE);
request.AddHeader(
"Id"
, lblId.Text);
request.AddHeader(
"Content-Type"
,
"application/json"
);
IRestResponse result = restClient.Execute(request);
}
Secondly, I want to display return value from Api
Thanks
Reply
Answers (
4
)
signal app integrate with asp.net mvc
Button update for DropDownList added dinamically in GridView