您好,我正在尝试使用其余的Web服务,并在chtml中公开它,但是当我启动应用程序并且不理解时,我一直收到此错误。是因为缺少库或依赖项吗?
Absencecontroller:
documents
我的index.chtml:
using ProjectWeb.Models;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Mvc;
namespace ProjectWeb.Controllers
{
public class AbsenceController : Controller
{
// GET: Absence
public ActionResult Index()
{
HttpClient Client = new System.Net.Http.HttpClient();
Client.BaseAddress = new Uri("http://localhost:18080/PiDev-web/rest/absence/");
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = Client.GetAsync("all").Result;
if (response.IsSuccessStatusCode)
{
ViewBag.result = response.Content.ReadAsAsync<IEnumerable<Absence>>().Result;
///ViewBag.result1 = response.Content.ReadAsStringAsync().Result;
}
else
{
ViewBag.result = "error";
}
return View("index");
}
// GET: Absence/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: Absence/Create
public ActionResult Create()
{
return View();
}
// POST: Absence/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Absence/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: Absence/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Absence/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: Absence/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
当我通过在浏览器上按视图启动它时,出现此错误 enter image description here
当我按它时,错误是由于:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>index</title> </head> <body> <br /> <h3> @Html.ActionLink("Ajouter Absence ", "Create") </h3> <hr /> <table class="table"> <tr> <th>ID</th> <th>Nom</th> <th>Action</th> </tr> @foreach (var h in ViewBag.result) { <tr> <td>@h.idAbsence</td> <td>@h.cause</td> <td> @Html.ActionLink("Edit", "Edit", new { id = h.idAbsence }) | @Html.ActionLink("Details", "Details", new { id = h.idAbsence }) | @Html.ActionLink("Delete", "Delete", new { id = h.idAbsence }) </td> </tr> } </table> </body> </html>
如果您熟悉此错误,请帮助我
答案 0 :(得分:0)
在您的情况下,AggregateException可能意味着任务引发了异常。您可以在调试选项下打开“打破所有异常”,然后再次运行以找出原始异常。
哦,然后取消选择“启用我的代码”
答案 1 :(得分:0)
我只是遇到了同样的例外; 内容标题包含Content-Type = application / json; charset = ISO-8859-1
response.Content.ReadAsStringAsync()工作正常,并得到我的变音符号'é'
但是
response.Content.ReadAsAsync
看起来像是Microsoft错误。解决方法是先使用ReadAsStringAsync,然后再解析json