Sounouk
Sounouk

Reputation: 95

The parameter is not passed from the view to the action

Here is the dropdownlist which contains the parameter (selected value) that I would like to pass to the view:

<select id="sltBiblioSite" name="sltBiblioSite">
            <option>Sélectionnez un  BiblioSite</option>
            @*Iterating BiblioSite Model*@
            @foreach (var item in Model)
            {
                <option>
                    @item.NomSite
                </option>
            }
        </select>

Here is where I tried different things (see commented code below) to pass the parameter to the fucntion:

 var selectedBiblioSiteName;

$("#sltBiblioSite").change(function () {

    //selectedBiblioSiteName = $("#sltBiblioSite").val();
    //selectedBiblioSiteName = $("#sltBiblioSite").val().trim();
    //selectedBiblioSiteName = $("#sltBiblioSite option:selected").text();
    //selectedBiblioSiteName = $("#sltBiblioSite > option:selected").attr("value")
    ...
    }
});

and here is one of the functions who is supposed to pass the parameter by calling the partial view.

    function getReservationTable() {
    $.ajax({
        // Get Reservation PartialView
        url: "/Home/ReservationsToPartialView",
        type: 'Get',
        data: { biblioSiteName: selectedBiblioSiteName },
        success: function (data) {
            $("#reservationDetailTable").empty().append(data);
        },
        error: function () {
            alert("something seems wrong");
        }
    });
}

I tried to hardcode the parameter in the action and it's working. The problem seems to be in the view but I don't know where, please help me to fix this problem.

        public ActionResult ReservationsToPartialView(string biblioSiteNom)
    {
        //biblioSiteNom = "La feuille de chene";
        var reservationByBiblio = ReservationLinq.GetReservationByBiblioSite(biblioSiteNom);
        return PartialView("ReservationPV", reservationByBiblio);
    }

Upvotes: 0

Views: 26

Answers (1)

Trimack
Trimack

Reputation: 4233

I haven't done this in a long time, so I might be completely wrong but I think you are passing wrong parameter name. In your ajax request you have biblioSiteName and in your actions its biblioSiteNom.

Also try some alert before calling the ajax to see whether the read parameter biblioSiteName is correct.

Upvotes: 2

Related Questions