簡體   English   中英

如何在asp.net中將ID動態設置為ajax.Actionlink?

[英]How to dynamically set id to ajax.Actionlink in asp.net?

我有一個項目列表,每個項目中都有一個Ajax.ActionLink,我想做的是動態設置每個操作鏈接的ID(項目ID)。

@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",
@id=@Tour.id

但這給了我錯誤,因為我在jquery(客戶端)中使用razon語法(服務器端),對此有什么辦法嗎?

我之前發布的動態動作鏈接ajax:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM