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

Call PartialViewMethod from controller using ajax

$
0
0

I have the View.cshtml with dropdowlist and button

div class="form-group">
            @Html.Label("Domki", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model=>model.SelectedHouseDetailsId,Model.Houses, new { @id = "MyList" })
            </div>

                   
            </div>

        <input id="Select" type="button"
               value="Wybierz domek" />

I by selecting item from list and clicking button i want to call metioned eariler method

public ActionResult GetView(int id,string name)
        {
            ReservationHouseDetails houseDetails=null;
            repository.GetHousesForReservation(id).Where(item => item.Name.Equals(name)).ForEach(item => houseDetails = new ReservationHouseDetails()
            {
                House=item,
                Meal = repository.GetHouseMealForReservation(item.Id),
                Participants = repository.GetParticipantsHouseForReservation(item.Id)
            });
            return PartialView("~/Views/ClientReservations/ReservationHouseDetails.cshtml", houseDetails);
        }

And this execution shoud update div container in View.cshtml

<div id="SelectHouse" class="SelectHouse">

        </div>

Ajax script

    <script type="text/javascript">
        $("#Select").click(function () {
            alert('hello')
            $.ajax({
                url: "~/Controllers/ClientReservations/GetView",
                type: "GET",
                dataType: "text",
                data: { id: $("#Model.Reservation.Id").text(), name: $("#SelectedHouseDetailsId option:selected").text() },
                success: function(result){
                    $('#SelectHouse').html(result)
            }})
        });
    </script>

When I click button there is no reposne. Is structure of ajax script wrong and passed arguments?


Viewing all articles
Browse latest Browse all 5678

Trending Articles



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