How to make Modal pop up pass to Controller before loading the page?
I can make the modal pop work even without passing controller but I need to set the model data since my modal suppose to be my create and update form.
Here is the button to call modal:
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_upload_image" >Upload Image </button>
<div class="modal fade" id="kt_modal_upload_image" tabindex="-1" aria-hidden="true">
.....
</div> I tried indicating the controller and action in button but still didnt work:
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_upload_image" asp-controller="Image" asp-action="UpsertModal">
Upload Image</button> Controller:
[HttpGet]
public IActionResult UpsertModal(int? id)
{
.....
return View();
} Replies (6)
do you have any sample code to return PartialView from asp .net core Controller using metronic 8 .net core version? i need to populate the Model first before I display the modal. Please, Thank you
Hi,
Sorry for the late reply.
If you just want to return PartialView in your Controller then you can use the example below.
[HttpGet("/")]
public IActionResult Index()
{
return PartialView("~/Views/Partials/Modals/_UpgradePlan.cshtml");
} Regards,
Lauris Stepanovs,
Keenthemes Support Team
Thank you so much for your response. My main issue is this code is not hitting the controller but it shows the modal.
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#kt_modal_upload_image" asp-controller="Image" asp-action="UpsertModal" asp-route-> Upload Image </button>
Hi,
You can toggle your modal from javascript code.
Firstly create modal instance.
var myModal = new bootstrap.Modal(document.getElementById("your modal id"), {
keyboard: false
}) Then use this instance to show or hide your modal.
myModal.show()
myModal.hide() Regards,
Lauris Stepanovs,
Keenthemes Support Team
Hi.
Which app type are you currently working on? Angular, React, Laravel or etc.?
Regards