kendo mvc window Object doesn't support property or method 'open'

3 posts, 1 answers
  1. Randy
    Randy avatar
    2 posts
    Member since:
    Jun 2011

    Posted 17 Jun Link to this post

    I am trying to open a kendo window based on input from a form. I am getting this error:

    JavaScript runtime error: Object doesn't support property or method 'open'

    The error occurs when win.open(); is called in the JavaScript in the view as listed below. Any help would be great.

    Here is my controller:

    using Kendo.Mvc.UI;
    using Kendo.Mvc.Extensions;
    using KendoGridAjaxBinding.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
     
    namespace KendoGridAjaxBinding.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                TheModel m = new TheModel();
     
                return View(m);
            }
     
            public ActionResult Search( TheModel m)
            {
                if (m.Name != string.Empty)
                {
                    ViewData["OpenGrid"] = "OpenGrid";
                }
                return View("Index", m);
            }
     
        }
    }

    Here is my view:

    @using System
    @using System.Web
    @using System.Web.Mvc
    @using System.Web.Razor
    @using Kendo.Mvc.UI
    @using KendoGridAjaxBinding.Models
     
    @model TheModel
     
    @using (Html.BeginForm("Search", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {
        <label for="textinput">Name</label>@Html.TextBoxFor(model => model.Name, new { @class = "input-xs form-control", placeholder = "Name", type = "text" })<br />
        <label for="textinput">Address</label>@Html.TextBoxFor(model => model.Address, new { @class = "input-xs form-control", placeholder = "Address", type = "text" })<br />
        <label for="textinput">City</label>@Html.TextBoxFor(model => model.City, new { @class = "input-xs form-control", placeholder = "City", type = "text" })<br />
        <label for="textinput">State</label>@Html.TextBoxFor(model => model.State, new { @class = "input-xs form-control", placeholder = "State", type = "text" })<br />
        <button id="Search" class="btn btn-primary">Search</button>
    }
     
     
     
    @(Html.Kendo().Window()
        .Name("window")
        .Width(630)
        .Height(315)
        .Draggable()
        .Resizable()
        .Title("Test Test Test")
        .Actions(actions => actions.Pin().Refresh().Maximize().Close())
        .Visible(false)
    )
     
    <script type="text/javascript">
        var messageX = '@ViewData["OpenGrid"]';
        if (messageX = "OpenGrid")
        {
            $("#window").kendoWindow();
            var win = $("#window").data("kendoWindow");
     
            var win = $("#window")
            if (win != null)
            {
                win.open();
            }
        }
     
    </script>

    The Model:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    namespace KendoGridAjaxBinding.Models
    {
        public class TheModel
        {
            public string Name { get; set; }
            public string Address { get; set; }
            public string City { get; set; }
            public string State { get; set; }
        }
    }

    Thanks in advance,

    rstinson

  2. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    680 posts

    Posted 21 Jun Link to this post

    Hello,

    Thanks for contacting Telerik support.

    I tested your code and updated it a little in order to call in a proper way the open method:

    @(Html.Kendo().Window()
        .Name("window")
        .Width(630)
        .Height(315)
        .Draggable()
        .Resizable()
        .Title("Test Test Test")
        .Actions(actions => actions.Pin().Refresh().Maximize().Close())
        .Visible(false)
    )
     
    <script type="text/javascript">
        $(document).ready(function() {
                $("#window").kendoWindow();
                var win=$("#window").data("kendoWindow");
                if(win!=null) {
                    win.open();
                }
        });
    </script>

    In the bellow code, i shown what is removed, as you do not need to set the var for a second time:

    var win = $("#window").data("kendoWindow");
      
            var win = $("#window")

    And also, the same behavior  run in dojo: http://dojo.telerik.com/iPEtA/2

    Regards,
    Bozhidar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Randy
    Randy avatar
    2 posts
    Member since:
    Jun 2011

    Posted 21 Jun in reply to Bozhidar Link to this post

    That got it. I should have seen that. I think I was looking at it to long to see clearly.

     

    Many thanks!!!

Back to Top