Hallo Leute, ich bin neu hier. Ich habe ein kleines Problem, das meine HomeController
und ich werde Get und Create mit Web-API, aber ich kann nicht finden und schreiben ein Bearbeiten/Details und Löschen. Erstellen und Index für Bearbeiten und LöschenWeb Api und ASP.Net MVC
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
List<Product1Model> lst =new List<Product1Model>();
HttpClient Client = new HttpClient();
Client.BaseAddress = new Uri("http://localhost:19440/");
Client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage responsive = Client.GetAsync("api/Product1").Result;
if (responsive.IsSuccessStatusCode)
{
lst = responsive.Content.ReadAsAsync<List<Product1Model>>().Result;
}
return View(lst);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Product1Model model)
{
HttpClient Client = new HttpClient();
Client.BaseAddress = new Uri("http://localhost:19440/");
Client.PostAsJsonAsync<Product1Model>("api/Product1",model)
.ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
return RedirectToAction("index");
}
}