Switching component does not work in a PartialView - Asp.Net MVC











up vote
0
down vote

favorite












I am having problems with the data-plugin switchery (Remark component bootstrap) 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 (#modalGeneric) opened by a partialview, it does not work:



In a Normal View:
enter image description here



In a PartialView (Problem):



enter image description here



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

}


Layout.cshtml:



<div class="modal fade modal-primary" id="modalGenerica" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="contentModal">
</div>
</div>
</div>
</div>


I tried giving an override in partialview, but it did not work. I think something is missing, or there is some problem with the script.



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

</script>









share|improve this question
























  • Don't you need to activate the plugin after the modal loads the content(dynamically I guess) ?
    – Shyju
    Nov 15 at 20:06










  • This is already happening. I had a similar problem using selectpicker, but I was directed to do this override in the partialview and it worked. The problem is that I am not able to do the same with the switchery because I do not know if it is correct to use switcheryParent in the script ....
    – Master JR
    Nov 15 at 21:09










  • @Master JR i cannot seem to be able to find the tag that has the id modalGenerica. Can you try to use the same script but without the switcheryParent ?
    – Nick Polyderopoulos
    Nov 15 at 22:23










  • @Nick Polideropoulos The modal "modalGenerica" ​​is in _Layout.cshtml .... The other plugins are located within the modal. Just can not make the switchery plugin work ... I think I'm having trouble setting the switcheryParent property. Does it exist? Or was it another name? I updated the post above with the modal window script
    – Master JR
    Nov 15 at 22:30












  • @MasterJR From the documentation here: abpetkov.github.io/switchery i cannot seem to be able to find this option that you are passing. Am i looking on the wrong library ?
    – Nick Polyderopoulos
    Nov 15 at 22:37















up vote
0
down vote

favorite












I am having problems with the data-plugin switchery (Remark component bootstrap) 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 (#modalGeneric) opened by a partialview, it does not work:



In a Normal View:
enter image description here



In a PartialView (Problem):



enter image description here



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

}


Layout.cshtml:



<div class="modal fade modal-primary" id="modalGenerica" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="contentModal">
</div>
</div>
</div>
</div>


I tried giving an override in partialview, but it did not work. I think something is missing, or there is some problem with the script.



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

</script>









share|improve this question
























  • Don't you need to activate the plugin after the modal loads the content(dynamically I guess) ?
    – Shyju
    Nov 15 at 20:06










  • This is already happening. I had a similar problem using selectpicker, but I was directed to do this override in the partialview and it worked. The problem is that I am not able to do the same with the switchery because I do not know if it is correct to use switcheryParent in the script ....
    – Master JR
    Nov 15 at 21:09










  • @Master JR i cannot seem to be able to find the tag that has the id modalGenerica. Can you try to use the same script but without the switcheryParent ?
    – Nick Polyderopoulos
    Nov 15 at 22:23










  • @Nick Polideropoulos The modal "modalGenerica" ​​is in _Layout.cshtml .... The other plugins are located within the modal. Just can not make the switchery plugin work ... I think I'm having trouble setting the switcheryParent property. Does it exist? Or was it another name? I updated the post above with the modal window script
    – Master JR
    Nov 15 at 22:30












  • @MasterJR From the documentation here: abpetkov.github.io/switchery i cannot seem to be able to find this option that you are passing. Am i looking on the wrong library ?
    – Nick Polyderopoulos
    Nov 15 at 22:37













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am having problems with the data-plugin switchery (Remark component bootstrap) 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 (#modalGeneric) opened by a partialview, it does not work:



In a Normal View:
enter image description here



In a PartialView (Problem):



enter image description here



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

}


Layout.cshtml:



<div class="modal fade modal-primary" id="modalGenerica" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="contentModal">
</div>
</div>
</div>
</div>


I tried giving an override in partialview, but it did not work. I think something is missing, or there is some problem with the script.



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

</script>









share|improve this question















I am having problems with the data-plugin switchery (Remark component bootstrap) 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 (#modalGeneric) opened by a partialview, it does not work:



In a Normal View:
enter image description here



In a PartialView (Problem):



enter image description here



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

}


Layout.cshtml:



<div class="modal fade modal-primary" id="modalGenerica" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="contentModal">
</div>
</div>
</div>
</div>


I tried giving an override in partialview, but it did not work. I think something is missing, or there is some problem with the script.



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

</script>






javascript asp.net-mvc twitter-bootstrap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 22:33

























asked Nov 15 at 20:04









Master JR

1316




1316












  • Don't you need to activate the plugin after the modal loads the content(dynamically I guess) ?
    – Shyju
    Nov 15 at 20:06










  • This is already happening. I had a similar problem using selectpicker, but I was directed to do this override in the partialview and it worked. The problem is that I am not able to do the same with the switchery because I do not know if it is correct to use switcheryParent in the script ....
    – Master JR
    Nov 15 at 21:09










  • @Master JR i cannot seem to be able to find the tag that has the id modalGenerica. Can you try to use the same script but without the switcheryParent ?
    – Nick Polyderopoulos
    Nov 15 at 22:23










  • @Nick Polideropoulos The modal "modalGenerica" ​​is in _Layout.cshtml .... The other plugins are located within the modal. Just can not make the switchery plugin work ... I think I'm having trouble setting the switcheryParent property. Does it exist? Or was it another name? I updated the post above with the modal window script
    – Master JR
    Nov 15 at 22:30












  • @MasterJR From the documentation here: abpetkov.github.io/switchery i cannot seem to be able to find this option that you are passing. Am i looking on the wrong library ?
    – Nick Polyderopoulos
    Nov 15 at 22:37


















  • Don't you need to activate the plugin after the modal loads the content(dynamically I guess) ?
    – Shyju
    Nov 15 at 20:06










  • This is already happening. I had a similar problem using selectpicker, but I was directed to do this override in the partialview and it worked. The problem is that I am not able to do the same with the switchery because I do not know if it is correct to use switcheryParent in the script ....
    – Master JR
    Nov 15 at 21:09










  • @Master JR i cannot seem to be able to find the tag that has the id modalGenerica. Can you try to use the same script but without the switcheryParent ?
    – Nick Polyderopoulos
    Nov 15 at 22:23










  • @Nick Polideropoulos The modal "modalGenerica" ​​is in _Layout.cshtml .... The other plugins are located within the modal. Just can not make the switchery plugin work ... I think I'm having trouble setting the switcheryParent property. Does it exist? Or was it another name? I updated the post above with the modal window script
    – Master JR
    Nov 15 at 22:30












  • @MasterJR From the documentation here: abpetkov.github.io/switchery i cannot seem to be able to find this option that you are passing. Am i looking on the wrong library ?
    – Nick Polyderopoulos
    Nov 15 at 22:37
















Don't you need to activate the plugin after the modal loads the content(dynamically I guess) ?
– Shyju
Nov 15 at 20:06




Don't you need to activate the plugin after the modal loads the content(dynamically I guess) ?
– Shyju
Nov 15 at 20:06












This is already happening. I had a similar problem using selectpicker, but I was directed to do this override in the partialview and it worked. The problem is that I am not able to do the same with the switchery because I do not know if it is correct to use switcheryParent in the script ....
– Master JR
Nov 15 at 21:09




This is already happening. I had a similar problem using selectpicker, but I was directed to do this override in the partialview and it worked. The problem is that I am not able to do the same with the switchery because I do not know if it is correct to use switcheryParent in the script ....
– Master JR
Nov 15 at 21:09












@Master JR i cannot seem to be able to find the tag that has the id modalGenerica. Can you try to use the same script but without the switcheryParent ?
– Nick Polyderopoulos
Nov 15 at 22:23




@Master JR i cannot seem to be able to find the tag that has the id modalGenerica. Can you try to use the same script but without the switcheryParent ?
– Nick Polyderopoulos
Nov 15 at 22:23












@Nick Polideropoulos The modal "modalGenerica" ​​is in _Layout.cshtml .... The other plugins are located within the modal. Just can not make the switchery plugin work ... I think I'm having trouble setting the switcheryParent property. Does it exist? Or was it another name? I updated the post above with the modal window script
– Master JR
Nov 15 at 22:30






@Nick Polideropoulos The modal "modalGenerica" ​​is in _Layout.cshtml .... The other plugins are located within the modal. Just can not make the switchery plugin work ... I think I'm having trouble setting the switcheryParent property. Does it exist? Or was it another name? I updated the post above with the modal window script
– Master JR
Nov 15 at 22:30














@MasterJR From the documentation here: abpetkov.github.io/switchery i cannot seem to be able to find this option that you are passing. Am i looking on the wrong library ?
– Nick Polyderopoulos
Nov 15 at 22:37




@MasterJR From the documentation here: abpetkov.github.io/switchery i cannot seem to be able to find this option that you are passing. Am i looking on the wrong library ?
– Nick Polyderopoulos
Nov 15 at 22:37

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327143%2fswitching-component-does-not-work-in-a-partialview-asp-net-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327143%2fswitching-component-does-not-work-in-a-partialview-asp-net-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?