1

enter image description here

My current structure has a layout with header, body and footer. Inside the body load a view using ajax to call for a action controller returning a Json and painting a tree view. When user click on the tree view the footer should load the detailed information. But isnt working, my guess is because the scripts section isnt render properly.

Right now the script are in the layout without bundles or anything and work ok on the Main body because I use Jquery and a Tree to load the Json data.

But in the partial View get an error. I could write a @section scripts area and copy all the script from the layout in the Partial View but why should I duplicate the code?

enter image description here

The worst part is only give me problem in the production enviroment ... on my devolpment enviroment works ok.

enter image description here

So the questions:

  • Why the main view can see the scripts define on the Layout but the Partial View Doesnt?

  • Why my development enviroment work ok, but productions doesnt?

  • What should I do to solve this?

EDIT: More testing.

This is a test View, this render in the Body. But I need include script section otherwise the dialog doesnt show, even when layout have the scripts too.

@{
    ViewBag.Title = "TreeDetails";    
}
<html>
<head>
    <title>@ViewBag.Title</title>
</head>
<body>
    <h2>TEST PAGE</h2>

    <script>

        // Your code goes here.
        $(document).ready(function () {
            console.log("before dialog");
            $("#dialog").dialog();
            console.log("after dialog");
        })
    </script>

    <div id="dialog" title="Basic dialog">
        <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>

</body>
</html>

@section scripts {
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
}
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
  • Do you have your `treeview` script loaded also within the Layout? is that done with the `@scripts` section or just with a regular ` – David Espino Jun 21 '16 at 00:14
  • @DavidEspino I dont have @script section yet. I only have script tags in the head section of my layout, there include the jquery.js. Body View have a script loading the tree view, but `jstree.js` is also declared in the Layout. Foot section have some jquery.tabs, and there is where is failing. – Juan Carlos Oropeza Jun 21 '16 at 00:22
  • Ok more info... when the error occurs? Is it on load? whenever you click something?... can you paste the order on how your scripts are rendered? it seems that `dialog` is undefined maybe a `jquery.ui` function? is that already declared on the output html when you load your page? – David Espino Jun 21 '16 at 00:26
  • @DavidEspino I include a View sample. Here I need include the script.section otherwise the dialog doesnt show. This render direct into the Body, not using PartialView. – Juan Carlos Oropeza Jun 21 '16 at 00:34
  • Can you try moving those scripts on your @section scripts to the layout as regular ` – David Espino Jun 21 '16 at 00:39
  • @DavidEspino All my scrips are inside the head tags of the Layout. Only at the end there are `@Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required:false)` – Juan Carlos Oropeza Jun 21 '16 at 00:59
  • If you know a tutorial about this I will take it :( – Juan Carlos Oropeza Jun 21 '16 at 01:00
  • I think the only thing you require is move the jquery scripts to your layout as a regular ` – David Espino Jun 23 '16 at 05:34

1 Answers1

0

It seems a run time error due to an unrecognized jquery function.. try to move your link reference to jquery from your view @section area in the layout header..

Ciro Corvino
  • 2,038
  • 5
  • 20
  • 33