0

Открытие формы в модальном окне. Страница на которой вызываем окно:

<a asp-action="Create" class="btn btn-primary" data-toggle="modal" data-target="#modal">
  Добавить
</a>
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
    <div class="modal-content">

    </div>
</div>

И сама страница формы:

@model CrmEnergo.Models.ContractorPersonal
@{
    Layout = null;
}
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title">Создать</h4>
    <small class="font-bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</small>
</div>
<div class="modal-body">
    <form asp-action="Create">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <div class="form-group">
            <label asp-for="LastName" class="control-label"></label>
            <input asp-for="LastName" class="form-control" />
            <span asp-validation-for="LastName" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="FirstName" class="control-label"></label>
            <input asp-for="FirstName" class="form-control" />
            <span asp-validation-for="FirstName" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="Post" class="control-label"></label>
            <input asp-for="Post" class="form-control" />
            <span asp-validation-for="Post" class="text-danger"></span>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-white" data-dismiss="modal">Закрыть</button>
    <button type="button" class="btn btn-primary">Сохранить</button>
</div>

Все это прекрасно работало и работает в Bootstrap 3.7 но в Bootstrap 4 открывается только пустое окно, загрузка самой формы не происходит. Кто то решал уже эту проблему?

1 ответ 1

1

Нашел ответ на английском.

В версии 4 убрали загрузку по умолчанию. Теперь нужно обрабатывать отдельно в скрипте.

<script>
    $('#modal').on('show.bs.modal', function (e) {
        $(this).find('.modal-content').load(e.relatedTarget.href);
    });
</script>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.