大家好我是新來的。我有一個小問題,這是我的HomeController
,我將使用Web API進行獲取和創建,但是我無法找到並編寫編輯/詳細信息和刪除。Web Api和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");
}
}