How to debug a Javascript document.ready modal dialog that is defined as a razor?

My web app is one of those one page apps that replaces content <div>

via ajax. In the case when we want to show a modal dialog to the user, this function is called:

function OpenWindow(name, title, params) 
{
    var winParams = SetWindowParameters(name, title, params);
    var container = $('div.k-content[id=\'' + name + '\']');

    if (container.length > 0) 
        container.data("kendoWindow").destroy();

    container = $('<div/>', { id: name }).css('display', 'none');

    container.appendTo($('body'))

    if (params.content) 
        container.html(params.content);

    var window = container.kendoWindow(winParams);

    window.data("kendoWindow").center().open();
}

      

One sampling value for params

is:

params = { content: response, draggable: true, wizard: true };

      

And response

contains the result from public ActionResult ShowSomePopup

, which returns an object ViewResult

.

So another function makes an ajax request, returns some HTML from the server and passes that response object to OpenWindow

.

This view I am returning is a razor view. The cshtml file looks something like this:

<div id="SomeDiv">
    <!-- the rest of the form -->
</div>

<script type="text/javascript">
    $(document).ready(function ()
    {
        //some code
    });
</script>

      

I found:

The only solution I have found is to simply move the content of the cshtml script to a JS file and call this function from the cshtml $(document).ready

script. But it's a colossal pain in the butt when I have hundreds of view files; I can’t take the time to go through and move everything.

Question: How can I use Chrome to debug the modal dialog's document.ready function that is defined as a razor?

+3


source to share


1 answer


Write a "debugger" in js in the cshtml file for Chrome to hit the breakpoint, and then you can navigate when the browser developer tools open.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
  <script>
    
    $(document).ready(function () {
      debugger;
      alert("Hello world");
    })
  
  </script>
</div>
      

Run code


Other links: https://www.w3schools.com/jsref/jsref_debugger.asp

-1


source







All Articles