This question is locked. New answers and comments are not allowed.
I have a view with a dropdown list and a button to open a modal window where there is a text field and Save & Cancel buttons.
I'm loading the contents of the window from a partial. Within the partial, clicking Save does an ajax post and returns the saved index and name of the item. All the above works, but I can't append the newly saved item to the dropdownlist on the parent form - 'this.parent is null or not an object'. The window close works fine, so is it that I'm just not getting the DropDownList correctly? Is there an alternate way to do this?
The View (the relevent bits):
The Partial:
I'm loading the contents of the window from a partial. Within the partial, clicking Save does an ajax post and returns the saved index and name of the item. All the above works, but I can't append the newly saved item to the dropdownlist on the parent form - 'this.parent is null or not an object'. The window close works fine, so is it that I'm just not getting the DropDownList correctly? Is there an alternate way to do this?
The View (the relevent bits):
... <div class="editor-field"> @Html.DropDownListFor(model => model.SystemKeyID, new SelectList(ViewBag.SystemKeys, "SystemKeyID", "Name", Model.SystemKeyID), "--Select--") @Html.ValidationMessageFor(model => model.SystemKeyID) <button id="add-system-key">Add</button> </div>...@{ Html.Telerik().Window() .Name("Window") .Draggable(true) .Modal(true) .Buttons(b => b.Close()) .Content("") .Width(300) .Height(80) .Visible(false) .Render();}...@{ Html.Telerik().ScriptRegistrar() .OnDocumentReady(@<text> var windowElement = $('#Window'); var addSystemKeyButton = $('#add-system-key'); addSystemKeyButton .bind('click', function(e) { OpenAddKeyWindow('Add Key'); }) .toggle(!windowElement.is(':visible')); </text>);}...<script language="javascript" type="text/javascript"> function OpenAddKeyWindow(title) { $("#Window .t-window-title").html(title); $.get('/CMS/CMSHTML/AddKeyPartial', function (data) { var window = $("#Window").data("tWindow"); window.content(data); window.center(); window.open(); }); }</script>The Partial:
@using (Html.BeginForm()){ <div id="content"> <p><input id="TextAddKey" name="TextAddKey" type="text" /></p> </div> <div align='right'> <button type="button" onclick="saveWindow(event);">Save</button> <button type="button" onclick="closeWindow(event);">Cancel</button> </div><script type="text/javascript"> function saveWindow(e) { $.post('/CMS/CMSHTML/CreateSystemKey', { TextAddKey: $('input[name=TextAddKey]').val() }, function (data) { if (data.Result == "success") { //Fails on next line this.parent.$('#SystemKeyID').append($('<option selected="selected"></option>').val(data.SystemKeyID).html(data.SystemKeyName)); }; this.parent.$("#Window").data("tWindow").close(); }, "json") } function closeWindow(e) { this.parent.$("#Window").data("tWindow").close(); }</script>}