0

I know that there are many threads for this topic. Searched many of them already several days(!)... getting crazy becuase of this. I checked these: Uncaught TypeError: Object #<Object> has no method 'dialog' Uncaught TypeError: Object [object Object] has no method 'dialog'

Cannot understand what I am doing wrong, need your help. Below is code which I am trying to make work.

Index.chtml

@{
    ViewBag.Title = "Home Page";
}

<br/>
<input type="button" value="Get Form" onclick="getForm()" />


<script type="text/javascript">
function getForm(){$('#dialog').dialog({
            autoOpen: true,
            width: 400,
            resizable: false,
            title: 'My Table',
            modal: true,
            open: function(event, ui) {

                $(this).load('@Url.Action("Index", "Home")');
            },
            buttons: {
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });
}</script>

<div id="dialog"></div>

Controller

public ActionResult _dialog()
    {
        return View();
    }

    public ActionResult Index()
    {
        return View();
    }

_dialog.chtml

<h3>Partial View code</h3>

_Layout.chtml

...
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="~/Scripts/jquery-ui-1.10.4.min.js"></script>
<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
...
Community
  • 1
  • 1
ADO_kg
  • 65
  • 2
  • 13
  • 1
    are you missing the link to the jquery UI library ? – Rob Sedgwick Feb 16 '14 at 14:16
  • Check that your external scripts are embedded properly in the rendered HTML code, and can actually be reached (no 404 or something like that). – CBroe Feb 16 '14 at 14:16
  • ^ yeah, copy the link (src) to the jquery ui lib and paste into your browser (with domain ), can you see it ? – Rob Sedgwick Feb 16 '14 at 14:18
  • @Rob Sedgwick the link [link]http://localhost:58196/Content/themes/base/jquery-ui.css is returning content of file. Same as: /Scripts/jquery-1.10.2.min.js, /Scripts/jquery-ui-1.10.4.min.js – ADO_kg Feb 16 '14 at 15:20
  • @user998878, okay. Are all your scripts **under** the markup they are trying to target ? - eg $("#dialog") will not return the node if it hasn't been created yet. – Rob Sedgwick Feb 16 '14 at 15:32
  • @Rob Sedgwick, I did not get what you mean "under the markup". – ADO_kg Feb 16 '14 at 15:36
  • After that, ( in case you didn't know ) - make sure that the ui libary you are linking to contains the 'dialog' method - it might not - the jquery ui libary is customisable. – Rob Sedgwick Feb 16 '14 at 15:36
  • re: 'under the markup' - you can't access an element- $("elementid") - if it is not yet been created - not saying that is the answer to your problem here, just eliminating that potential problem. – Rob Sedgwick Feb 16 '14 at 15:38
  • jquery-ui.css includes all controls (written on top of file), even I tried to put jquery.ui.dialog.css directly. I am trying to use last two samples from here - forums.asp.net/t/1879576.aspx – ADO_kg Feb 16 '14 at 16:13

1 Answers1

0

I suppose there are some incompatibilities between the versions of jquery and jquery UI you are using. Try with jQuery 2.0.0:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />

There might be some issues with jQuery UI 1.10.4 and jQuery > 2.0.0 like jQuery 2.1.0 for example.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Sorry, same error. If I remove line "@Scripts.Render("~/bundles/jquery")", javascript works but not as modal, content appears in the center of page. – ADO_kg Feb 16 '14 at 17:02
  • Why do you have `@Scripts.Render("~/bundles/jquery")` line? This will include jQuery once again. You should decide whether you want to use bundles or include the external scripts. If you use bundles then use `@Scripts.Render("~/bundles/jquery")` and after it use `@Scripts.Render("~/bundles/jqueryui")` and then place your custom script inside a `@section Scripts { .. }` section from your view. And get rid of all custom script inclusions like `` and `` which you are having. – Darin Dimitrov Feb 16 '14 at 17:04
  • лови пять!!! Thank you very much. Removed all bundles and worked. Now I understand what I was doing wrong. – ADO_kg Feb 16 '14 at 17:12