Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Asp Mvc + Ajax doesnt work !

$
0
0

Hello there, i need a big help here.

I have a View called Index

That when i select on an option, i will retrieve a list of boxes.

@model  ParkAr.ViewModels.ReservaBoxViewModel

@{
    ViewBag.Title = " ";
    Layout = "~/Views/Shared/_Layout.cshtml";
}<script src="~/Scripts/jquery-1.12.4.min.js"></script><script>$(document).ready(function () {$("#EstacionamientoSelect").change(function () {
                if ($('#EstacionamientoSelect').val() == 0) {$('#container-boxes').html("")
                } else {$.ajax({
                        type: 'GET',
                        url: '@Url.Action("VerBoxes")',
                        data: { EstacionamientoID: $('#EstacionamientoSelect').val() },
                        success: function (result) {$('#container-boxes').html(result);$('#divListaEstacionamientos').hide();
                        },
                        error: function () {
                            alert(xhr.status);
                            alert(thrownError);
                            alert(xhr.responseText);
                        }
                    });
                }
            });

        });
    </script><div class="form-group" id="divListaEstacionamientos" ><h2>Seleccione Estacionamiento</h2><p>Estacionamiento</p>
    @* @Html.DropDownList("Estacionamiento", new SelectList(Model.Select(e => e.Nombre).Distinct().ToList()), "EstacionamientoId", "Nombre", "Seleccione Estacionamiento", new { @class = "form-control" })-->*@<select id="EstacionamientoSelect"><option value="0">Seleccione un estacionamiento</option>
        @foreach (var park in @Model.Estacionamientos)
        {<option value="@park.EstacionamientoId">@park.Nombre</option>
        }</select></div><div id="container-boxes"></div>

Selection

So, when i select it here, it goes to the controller action VerBoxes

public ActionResult VerBoxes(string estacionamientoID)
{
            int id = Int32.Parse(estacionamientoID);
            var estacionamiento = _context.Estacionamientos
                   .Include(x => x.Boxes.Select(y => y.EstadoBox)).SingleOrDefault(x =>x.EstacionamientoId == id);

            return View(estacionamiento);
}

An the controller VerBoxes return the list of boxes to anotherview called VerBoxes

But it don´t see the list of boxes in the id #container-boxes.

@model ParkAr.Models.Estacionamiento

@{
    ViewBag.Title = "Index3";
    Layout = "~/Views/Shared/_Layout.cshtml";
}<script>
   function reservarBox(boxId){$.ajax({
                type: 'GET',
                url: '@Url.Action("ReservarBox")',
                data: { boxID: boxId, estacionamientoId: $('#EstacionamientoSelect').val() },
                success: function (result) { $('#container-boxes').html(result); },
                error: function () {
                    alert(xhr.status);
                    alert(thrownError);
                    alert(xhr.responseText);
                }
            });
        }</script><h2>Boxes del Estacionamiento @Model.Nombre</h2><div id="container-boxes"><p> Entre</p><div class="container-fluid"><div class="row">
            @for (var i = 0; i < Model.Boxes.Count; i++)
            {
                if (i > 0 && i % 12 == 0)
                {
                    @:</div><div class="row">
                }<div class="col-lg-1">@Html.TextBoxFor(x => x.Boxes[i].Value)</div>
            }</div></div>

 

Do you know that i am doing wrong??? Really appreciated in advance


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>