Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:12:13+00:00 2026-06-18T03:12:13+00:00

I have 2 Razor views where one is loading the other in a jQuery

  • 0

I have 2 Razor views where one is loading the other in a jQuery UI dialog. In the view that get loaded in the dialog; I am opening another jQuery UI dialog to display a message.

The objective is to close both the dialogs when message dialog Cancel button is clicked.

Razor code is as follows:

Main View

<button id="openModel" onclick="openModel()">

<div id="mainDialog" />

<script type="text/javascript">
    function openModel() {
        $('#mainDialog').dialog({
            open: function () {
                // loading "the secondary view in the model dialog"
                // url: controller-action url to load the second view
                $(this).load('url'); 
            }
        });
    }
</script>

Dialog View

<button id="messageOpener">Verify</button>

<div id="messageDialog" />

<script type="text/javascript">

    $(document).ready(function () {

        $("#messageOpener").click(function () {
            $("#messageDialog").dialog("open");
                return false;
        });

        $("#messageDialog").dialog({
            buttons: {
                Retry: function () {
                    $(this).dialog("close");
                },
                Cancel: function () {
                    // **** ?? must close both dialogs. ****
                }                
            },
            autoOpen: false,
        });
    });

</script>

I have tried following approaches to close the dialogs:

Approach 01:

$(".ui-dialog-content").dialog("close");

Approach 02:

$(this).dialog("close");
$("#mainDialog").dialog("close");

Approach 03:

$(".ui-dialog:visible").find(".dialog").dialog("close");

But all above does not close the dialogs as expected instead produces the following JS error:

Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method ‘close’
v.extend.error
(anonymous function)
v.extend.each
v.fn.v.each
e.fn.(anonymous function)
$.dialog.buttons.Cancel
r.click
v.event.dispatch
o.handle.u

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:12:15+00:00Added an answer on June 18, 2026 at 3:12 am

    Re-writing the code in the following way solve the problem..

    1. Main View

    <button id="openModel" onclick="openModel()">
    
    <div id="mainDialog" />
    
    <script type="text/javascript">
    
        var $modelDialog = $('#mainDialog').dialog({
            autoOpen: false,
            open: function () {
                // loading "the secondary view in the model dialog"
                // url: controller-action url to load the second view
                $(this).load('url'); 
            }
        });
    
        function openModel() {
            $modelDialog.dialog('open');    
        }
    
        function closeModel() {
            $modelDialog.dialog('close');    
        }
    
    </script>
    

    2. Dialog View

    <button id="messageOpener">Verify</button>
    
    <div id="messageDialog" />
    
    <script type="text/javascript">
    
        var $messageDialog;
    
        $(document).ready(function () {
    
            $("#messageOpener").click(function () {
                $messageDialog.dialog("open");
                    return false;
            });
    
            $messageDialog = $("#messageDialog").dialog({
                buttons: {
                    Retry: function () {
                        $messageDialog.dialog("close");
                    },
                    Cancel: function () {
                        // [!!]
                        $messageDialog.dialog("destroy");
                        closeModel();
                    }                
                },
                autoOpen: false,
            });
        });
    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one (razor) page that contain 5 different partial views. Each partial view
I have a razor cshtml view that uses jquery. I get following error during
I have a section of Razor code in one of my views that isn't
I have an odd problem with one of my Razor views in an ASP.NET
I am trying out the MVC3 Razor view engine, and one the features that
This one is strange...I have the following markup for a view using Razor view
I am working for asp.net MVC3 Razor view. I have created for dynamically loading
Using MVC3/Razor where would I put images that were specific to one view? I
I have on one of my views the following razor code: @if (item.PMApproved !=
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.