/
IamDeveloper
/
MyRecipeAppFront
Обзор
Документация
Войти
/
IamDeveloper
/
MyRecipeAppFront
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Controllers/IngredientController.cs
100 строк
3 KB
Dmitriy Urazlin
Добавьте файлы проекта.
09 авг 2026, 19:51
09 авг 2026, 19:51
e30eebb
Код
Авторство
О чём код?
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using MyRecipeAppFront.Class; using Newtonsoft.Json; using System.Net.Http.Headers; namespace MyRecipeAppFront.Controllers { public class IngredientController : Controller { // GET: IngredientController public async Task<ActionResult> Index() { HttpClient client = new() { BaseAddress = new Uri("http://localhost:8084/") }; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync("/api/ingredient"); var answer = await response.Content.ReadAsStringAsync(); answer = answer.Trim().Replace("\\\"", "\""); var ingrList = JsonConvert.DeserializeObject<IEnumerable<Ingredient>>(answer); ViewBag.Ingredients = ingrList; return View(); } // GET: IngredientController/Details/5 public ActionResult Details(int id) { return View(); } // GET: IngredientController/Create public ActionResult Create() { return View(); } // POST: IngredientController/Create [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create(IFormCollection collection) { try { return RedirectToAction(nameof(Index)); } catch { return View(); } } // GET: IngredientController/Edit/5 public ActionResult Edit(int id) { return View(); } // POST: IngredientController/Edit/5 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit(int id, IFormCollection collection) { try { return RedirectToAction(nameof(Index)); } catch { return View(); } } // GET: IngredientController/Delete/5 public ActionResult Delete(int id) { return View(); } // POST: IngredientController/Delete/5 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Delete(int id, IFormCollection collection) { try { return RedirectToAction(nameof(Index)); } catch { return View(); } } } }