I am trying to consume web service api via httpwebrequest and razor to show it in mvc view. in the mvc controller I have this code in which I want to consume the api
using EntradaElectronicaAlmacenApi.Services;
using System.IO;
using System.Net;
using System.Web.Mvc;
namespace EntradaElectronicaAlmacen.Controllers
{
public class InicioController : Controller
{
// GET: Inicio
public ActionResult Index()
{
return View();
}
// get: opciones
public ActionResult PantallaOpciones()
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://localhost:49851/api/motivo/motivos");
myReq.ContentType = "application/json";
var response = (HttpWebResponse)myReq.GetResponse();
string text;
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
var motivos = new MotivoService();
var result = motivos.ObtenerMotivos();
var rr = Json(new { motivos = text });
ViewData["motivos"] = rr;
return View();
}
}
}
and in the view I want to generate some buttons with the data that I want to consume from the api I have the following code.
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Pantalla Opciones</title>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Styles.css" rel="stylesheet" />
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
</head>
<body>
<div>
@if (ViewData["motivos"] != null)
{
foreach (var motivo in ViewData["motivos"] as List<EntradaElectronicaAlmacenApi.Infraestructura.Motivos>)
{
<div class="col-sm-3">
<button id="@motivo.Motivo_Id.ToString()-btn" class="boton3d2" data-toggle="modal" data-target="#PopUpAcceso">@motivo.Descripcion</button>
</div>
}
}
</div>
</body>
but it generates the following error
An exception of type 'System.InvalidOperationException' occurred in EntryElectronicaAlmacenApi.dll but was not handled in user code
Additional information: No connection string named 'EntryElectronicaAlmacenEntities' could be found in the application config file.
what could be the error that I investigated and I can not find ...