Ajax.ActionLink工作一次

时间:2014-01-24 23:43:51

标签: c# asp.net-mvc razor asp.net-ajax

我正在使用ActionLink做一些疯狂的事情。它工作一次,然后不会再次更新DIV。当我调试它时,代码会遍历所有内容,但更改不会出现在DIV中。

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

控制器代码:

   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");

    }

获取数据:

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;
}

1 个答案:

答案 0 :(得分:0)

您必须确保UpdateTargetId = VehicleScheduleEdit指向要更新的div元素的相应ID。

您还需要确保将PartialView放置在此div元素内,而不是div元素是PartialView的一部分。