简体   繁体   English

如何在asp.net中将ID动态设置为ajax.Actionlink?

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

I have a list of items and in each item I have a Ajax.ActionLink what I want to do is to set id of each action link dynamically (Item id). 我有一个项目列表,每个项目中都有一个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"})

my model is 我的模特是

HolidayPlanners.Models.Tour HolidayPlanners.Models.Tour

what I want to do is something like this 我想做的就是这样

@class= "tm-tours-box-1-link-right",
@id=@Tour.id

but it is giving me errors because I am using razon syntax(server side) inside jquery(client side) is there any way around to this? 但这给了我错误,因为我在jquery(客户端)中使用razon语法(服务器端),对此有什么办法吗?

Dynamic action link ajax, as I posted prior: 我之前发布的动态动作链接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: 模型:

 @model IEnumerable<Testy20161006.Controllers.CarModel>

More about my model: 有关我的模型的更多信息:

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