Функция редактирования бритвы с тем же видом - PullRequest
0 голосов
/ 16 марта 2020

Я создаю эту функцию редактирования, которая использует модальный интерфейс. Но я не знаю, я не хочу новый вид, я хочу использовать вид Добавить. Могу ли я в ActionResult найти индекс, исходящий из представления?

Представление

 $(".references-list").on("click", ".edit-reference", function () {
            var index = $(this).data('index');
            console.log(index);

            getAjax("@Url.Action("Edit", index)", function (data, index)
            {
                $("#add-reference-modal .modal-body").html(data);
                $("#add-reference-modal").modal('show');
            });

            return false;
        }); 

Контроллеры

  [HttpGet]
    public ActionResult Add()
    {
        return PartialView();
    }

    [HttpGet]
    public ActionResult Edit(string index)
    {

        return PartialView();
    }

enter image description here

1 Ответ

0 голосов
/ 17 марта 2020

Вы можете передать «index» вашему контроллеру следующим образом:

        $(".references-list").on("click", ".edit-reference", function () {
        var index = $(this).data('index');
        console.log(index);

        $.ajax({
            url: '/myController/myAction/', //add your controler and action
            method: 'GET',
            data: { index : index }, // can be written as data: { index : $(this).data('index') }
            begin: function () {
                console.log('Ajax onBegin fired');
            },
            success: function (returnData) {
                console.log(returnData);
                //handle your modal
                //$("#add-reference-modal .modal-body").html(returnData);
                //$("#add-reference-modal").modal('show');
            }
        });

        return false;
    }); 
...