I have partial view which I am calling in main view here is the code
@section scripts {
}
but on button click I see the console it says clickme is not defined even though its there.remember its in partial veiw
I have partial view which I am calling in main view here is the code
but on button click I see the console it says clickme is not defined even though its there.remember its in partial veiw
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhishek YadavRank #217 · 11.3K reputationPosted Aug 10, 2024, 3:57 AM EDT
Hello,
It seems like your issue with the
clickmefunction not being recognized might be due to how your scripts are included or scoped. Here are a few things you should check to resolve the issue:Script Inclusion: Make sure that your main layout includes
@RenderSection("scripts", required: false)so that scripts from partial views are correctly included.Script Order: Ensure that jQuery and SweetAlert2 libraries are loaded before your custom script. The script order matters for correct functionality.
Partial View Setup: Verify that your partial view’s
@section scriptsblock is correctly rendering the script. Check the browser’s page source to ensure it appears correctly.Ensure Script is Loaded Correctly
Check Script Location: Make sure that the partial view is being loaded into a page where jQuery and SweetAlert2 are also loaded. If these libraries are not included, your script won't work.
Scope of Scripts: Ensure that the scripts in the
@section scriptsblock of the partial view are correctly included in the main view. Typically,@section scriptsis included at the bottom of the main view’s layout.Script Registration: Confirm that the main view’s layout includes the
@RenderSection("scripts", required: false)line to ensure that scripts from partial views are rendered. This should be in your main layout view:@RenderSection("scripts", required: false)Example Setup
Main View Layout (e.g.,
_Layout.cshtml):Your Title @RenderBody() @RenderSection("scripts", required: false)Partial View (e.g.,
_PartialView.cshtml):Delete @section scripts { function clickme(info) { Swal.fire({ title: 'Confirmation', text: 'Are you sure you want to save this information?', icon: 'question', showCancelButton: true, confirmButtonText: 'Ok', cancelButtonText: 'Cancel' }).then((result) => { if (result.isConfirmed) { // Perform the action if the user confirms $("#optype").val(info); $("#parti").trigger('submit'); } }); } }If following these steps resolves the issue, please accept this response to close the thread. If you need further assistance, feel free to provide more details.
Mark TaborRank #914 · 2.3K reputationPosted Aug 10, 2024, 6:11 AM EDT
Dear Abhishek my script execution is already in good order but the issue persists the Sweet alert works for main view but not for partial view which i am calling in main view