I have a following code for the Delete action in my controller.
public HttpResponseMessage Delete(int id)
{
try
{
var course = TheRepository.GetCourse(id);
if (course == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
if (course.Enrollments.Count > 0)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, "Can not delete course, students has enrollments in course.");
}
if (TheRepository.DeleteCourse(id) && TheRepository.SaveAll())
{
return Request.CreateResponse(HttpStatusCode.OK);
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
How can I implement the delete action in my ViewEngine with Delete button and ID field in my .cshtml file.
Thanks in Advance.