Component switchery does not work on a Partialview - Asp.Net MVC

Asked

Viewed 31 times

0

I am having problems with data-plugin switchery (Remark bootstrap component) that does not want to work in partialviews. The interesting thing is that if it stays inside a normal view, it works perfectly, but when placed inside a modal window (#modalGenerica) opened by a partialview, it doesn’t work:

In a Normal view:

inserir a descrição da imagem aqui

In a Partialview (Problem):

inserir a descrição da imagem aqui

Code:

@model Retaguarda.Application.ViewModels.ContatoTipo.ContatoTipoViewModel
@{
    ViewData["Title"] = "_ContatoTipo";
}

<div class="panel">
    <div class="panel-body container-fluid pt-10 pl-15 pr-15">
        <div class="form-horizontal">
            <vc:summary />
            <div class="form-horizontal">
                <div class="form-group row">
                    <div class="col-md-6">
                        <label asp-for="Descricao" class="control-label">Descrição</label>
                        <input asp-for="Descricao" class="form-control text-uppercase" />
                        <span asp-validation-for="Descricao" class="text-danger"></span>
                    </div>
                </div>
                <div class="example">
                    <div class="float-left mr-20">
                        <input type="checkbox" id="mycheckbox" name="inputiCheckBasicCheckboxes" data-plugin="switchery"
                               checked />
                    </div>
                    <label class="pt-3" for="inputBasicOn">On</label>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    $('#mycheckbox').switchery({
        switcheryParent: $('#modalGenerica')
    });

</script>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

}

I tried to boot it in partialview but it didn’t work. I don’t know if there is even the property switcheryParent...

<script>
    $('#mycheckbox').switchery({
        switcheryParent: $('#modalGenerica')
    });

</script>

Does anyone know how to solve this problem? A hug to all and thank you!

  • It’s not because your partial doesn’t inherit the same master page as the views that in turn include the js and css of the component?

  • Where I could change to make the inheritance @Leandroangelo?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.