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" />
...
9
  • 1
    are you missing the link to the jquery UI library ? Commented Feb 16, 2014 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). Commented Feb 16, 2014 at 14:16
  • ^ yeah, copy the link (src) to the jquery ui lib and paste into your browser (with domain ), can you see it ? Commented Feb 16, 2014 at 14:18
  • @Rob Sedgwick the link [link]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 Commented Feb 16, 2014 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. Commented Feb 16, 2014 at 15:32

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, same error. If I remove line "@Scripts.Render("~/bundles/jquery")", javascript works but not as modal, content appears in the center of page.
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 <script src="http://code.jquery.com/jquery-latest.js"></script> and <script src="~/Scripts/jquery-ui-1.10.4.min.js"></script> which you are having.
лови пять!!! Thank you very much. Removed all bundles and worked. Now I understand what I was doing wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.