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
Luke Rayner
NA
7
4.2k
Web API and MVC Deleting data using MVC controller
Nov 19 2015 3:40 AM
Hi,
I have been making a project which involves a Web API and MVC, I have been able to connect my MVC project to my API allowing me to display data onto one of my views using a table.
I am struggling to create a delete function on my MVC project, I have made it pull a set of data from the table to a different view using the ID (i have created the view using the template you are given)
The code below is what i did in order to get that data
[HttpGet]
public ActionResult Delete(int id)
{
StudentModel Student = new StudentModel();
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:6193/");
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("api/students/" + id).Result;
if (response.IsSuccessStatusCode)
{
Student = response.Content.ReadAsAsync<StudentModel>().Result;
}
return View(Student);
}
Now i am trying to use the [HttpPost] to remove the data from my database i would be really grateful if anyone is able to help me out and keep it pretty simple so i am able to understand it.
Thanks
Reply
Answers (
2
)
Export Gridview Records to Text File Using ASP.Net C#..
original duplicate triplicate copy of crystal report