简体   繁体   中英

Ajax.ActionLink Works Once

I am doing something crazy with the ActionLink. It works once and then won't update the DIV again. When I debug it, the code goes through everything but the changes don't appear in the DIV.

@Ajax.ActionLink("Make/Model", "SortVehicle", "Exposure", new { an = agreementNumber, sortOrder = "make" }, new AjaxOptions() { UpdateTargetId = "VehicleScheduleEdit", InsertionMode=InsertionMode.Replace })

The controller code:

  public ActionResult SortVehicle(int an, string sortOrder) { switch (sortOrder) { case "year": sortOrder = "VehicleSchedule.AutoYear"; break; case "make": sortOrder = "VehicleSchedule.MakeModel"; break; default: sortOrder = "VehicleSchedule.MakeModel"; break; } VehicleScheduleViewModel objVehicleModel = new VehicleScheduleViewModel(); ViewData["VehicleScheduleViewModel"] = objVehicleModel.GetVehicleScheduleSorted(an, sortOrder); return PartialView("_VehicleSchedule"); } 

Getting the data:

public IEnumerable<VehicleScheduleViewModel> GetVehicleScheduleSorted(int agreementNumber, string sortOrder)
{
    var dataVehicle = (from VehicleSchedule in trustDB.LicensedAutos
            where VehicleSchedule.AgreementNumber == agreementNumber
            orderby (sortOrder)
            select new VehicleScheduleViewModel
            {
                RID = VehicleSchedule.RID,
                MakeModel = VehicleSchedule.MakeModel,
                IDNumber = VehicleSchedule.IDNumber,
                Location = VehicleSchedule.Location,
                AutoYear = VehicleSchedule.AutoYear,
                AutoValue = (double?)VehicleSchedule.AutoValue ?? 0,
                YearAddedtoDistrict = (DateTime?)VehicleSchedule.YearAddedtoDistrict ?? DateTime.Now,
                NumOfPassengers = (int?)VehicleSchedule.NumOfPassengers ?? 0,
                DistVehNo = VehicleSchedule.DistVehNo,
                NoCollision = VehicleSchedule.NoCollision,
                NoComp = VehicleSchedule.NoComp,
                InvalidVIN = VehicleSchedule.InvalidVIN,
                AgreementNumber = (float?)VehicleSchedule.AgreementNumber ?? 0
            });

    return dataVehicle;
}

You must make sure that your UpdateTargetId = VehicleScheduleEdit points to appropriate ID of the div element you want to update.

You also need to make sure that your PartialView is placed inside this div element and not that a div element is a part of your PartialView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM