2017-06-12 20 views
0

我有一個項目列表,並在每個項目中我有一個Ajax.ActionLink我想要做的就是動態地設置每個動作鏈接的id(Item id)。如何在asp.net中動態設置id到ajax.Actionlink?

@Ajax.ActionLink("Join","ajaxview",new{ id = tour.TourId},newAjaxOption 
HttpMethod = "GET", 
InsertionMode = InsertionMode.Replace, 
UpdateTargetId = "currentaction"},new{ 
@class= "tm-tours-box-1-link-right", 
@id="currentaction"}) 

我的模型是

HolidayPlanners.Models.Tour

我想要做的就是這樣的事情

@class= "tm-tours-box-1-link-right", 
@[email protected] 

但它給我的錯誤,因爲我在jQuery(客戶端)內使用razon語法(服務器端)有沒有辦法解決這個問題?

+0

嘿它不清楚你做了什麼錯誤。該頁面給服務器錯誤,所以它不能加載? jquery是否給出了某種錯誤?你在哪裏用這個實現jQuery?不清楚。 – Harry

回答

0

動態跳轉鏈接阿賈克斯,因爲我發佈前:

@car.CarMake, 
           "getUpdate", 
           new { carId = car.CarId }, 
           new AjaxOptions 
           { 
            UpdateTargetId = "result" + car.CarId, //use car.ID here? not sure 
            InsertionMode = InsertionMode.Replace, 
            HttpMethod = "GET" 
           }, new { @class = "getClick" }) 

型號:

@model IEnumerable<Testy20161006.Controllers.CarModel> 

更多關於我的模型:

public class CarModel 
{ 
    public int CarId { get; set; } 
    public string CarMake { get; set; } 
    public string theCarModel { get; set; } 
} 

public class HomeController : Controller 
{ 
    public PartialViewResult getUpdate(int carId) 
    { 
     CarModel carModel = new CarModel(); 
     switch (carId) 
     { 
      case 1: 
       carModel.CarId = 1; 
       carModel.CarMake = "updated11111Make"; 
       carModel.theCarModel = "updated11111Model"; 
       break; 
      case 2: 
       carModel.CarId = 2; 
       carModel.CarMake = "updated2Make"; 
       carModel.theCarModel = "updated22222Model"; 
       break; 
      case 3: 
       carModel.CarId = 3; 
       carModel.CarMake = "updated3Make"; 
       carModel.theCarModel = "updated33333Model"; 
       break; 
      default: 
       break; 
     } 
     return PartialView("_PartialView", carModel); 
    } 

    public ActionResult Index700() 
    { 
     IList<CarModel> carModelList = Setup(); 
     return View(carModelList); 
    } 

    private static IList<CarModel> Setup() 
    { 
     IList<CarModel> carModelList = new List<CarModel>(); 
     carModelList.Add(new CarModel { CarId = 1, CarMake = "VW", theCarModel = "model1" }); 
     carModelList.Add(new CarModel { CarId = 2, CarMake = "BMW", theCarModel = "model2" }); 
     carModelList.Add(new CarModel { CarId = 3, CarMake = "Ford", theCarModel = "model3" }); 
     return carModelList; 
    }