I am consuming a service to consult customer balances, it returns me as an answer an entity with these properties:
public string errorCodigoField { get; set; }
public string errorMensajeField { get; set; }
public decimal saldoRecargasField { get; set; }
public decimal saldoServiciosField { get; set; }
With an input button command to call the corresponding action, using jquery:
function Actualizar() {
$.ajax({
url: '/Recargas/ConsultaSaldo',
cache: false,
dataType: "html",
success: function (data) {
$('#saldosservicios').html(data);
}
});
After the call, I have the following condition in the action of the controller, where the return of the partial view is made:
if (saldoInfo.result.errorCodigoField == "00")
{
ViewBag.SaldoRecargas = Math.Round(Convert.ToDecimal(saldoInfo.result.saldoRecargasField), 2, MidpointRounding.AwayFromZero);
ViewBag.SaldoServicios = Math.Round(Convert.ToDecimal(saldoInfo.result.saldoServiciosField), 2, MidpointRounding.AwayFromZero);
return PartialView("ConsultaSaldo", new { _recargas = ViewBag.SaldoRecargas, _servicios = ViewBag.SaldoServicios });
}
else
{
return RedirectToAction("Index", "Recargas", new { Mensaje = "Ha ocurrido un error en la consulta" });
}
This would be the partial view:
@using (Html.BeginForm("ConsultaSaldo", "Recargas", FormMethod.Get, new { id = "formSaldos" }))
{
<div class="saldos">
<div class="saldosservicios">
<h4 class="nombresaldo">Saldo Servicios</h4>
@if (ViewBag.SaldoServicios != null)
{
<output class="totalsaldo" >@ViewBag.SaldoServicios</output>
}
</div>
<div class="saldosrecargas">
<h4 class="nombresaldo">Saldo Recargas</h4>
@if (ViewBag.SaldoRecargas != null)
{
<output class="totalsaldo">@ViewBag.SaldoRecargas</output>
}
</div>
<div>
<input class="btnConsultar" type="button" value="Consultar" onclick="Actualizar()"/>
</div>
</div>
}
And the call to the partial view from the main view I do it this way:
<div id="saldos-section">
@Html.Partial("ConsultaSaldo", new { SaldoRecargas = ViewBag.SaldoRecargas, SaldoServicios = ViewBag.SaldoServicios })
</div>
I have noticed in the debugging that the ViewBag does contain the expected values:
But for some reason the results are not shown on the screen. If you could give me some kind of guidance, I will be very grateful.
Greetings.