Note that there are some explanatory texts on larger screens.

plurals
  1. POKendo UI Grid Edit Template with AJAX call on change of DropdownList
    primarykey
    data
    text
    <p>I have an MVC3 Webapp with Kendo UI Grid. I am using the popup Template editing feature. I have a DropdownList in the Template view.</p> <p>Everything works great... Now I have added an <code>Instructions</code> div and a <code>Description</code> div that I want to use for instructions to the user, and the description of the selected item. These instructions depend upon the selected value of the Dropdown. Upon selecting an item in the dropdown, I need to make an ajax call to the controller to get the instructions and the description for the selection. I've tried a number of things but can't seem to get it to even fire off the call to the controller.</p> <p>Any help would be appreciated. Thanks, Murph</p> <p>Here is the grid code:</p> <pre><code>@(Html.Kendo() .Grid&lt;VW40.Web.Models.CompanyDefaultDataItemViewModel&gt;() .Name("Grid") .Columns(c =&gt; { c.ForeignKey(p =&gt; p.Type, (System.Collections.IEnumerable)@ViewBag.CompanyDefaultDataItemTypes, "CompanyDefaultDataItemTypeId", "Name").Title("Default Data Type").Width(200); c.Bound(p =&gt; p.Data); c.Bound(p =&gt; p.Instructions); c.Bound(p =&gt; p.Description); c.Command(command =&gt; { command.Edit(); command.Destroy(); }); }) .ToolBar(t =&gt; t.Create()) .Editable(editable =&gt; editable.Mode(GridEditMode.PopUp).TemplateName("CompanyDefaultDataItem").Window(w =&gt; w.Title("Add/Edit Company Default Data Item").HtmlAttributes(new { @style = "width:100px;" }))) .DataSource(ds =&gt; ds .Ajax() .Batch(false) .ServerOperation(false) .Events(events =&gt; events.Error("error")) .Model(m =&gt; m.Id(p =&gt; p.CompanyDefaultDataItemId)) .Read(read =&gt; read.Action("CompanyDefaultDataItems_Read", "Company", new { Id = @ViewBag.CompanyId })) .Update(update =&gt; update.Action("CompanyDefaultDataItem_Update", "Company")) .Create(update =&gt; update.Action("CompanyDefaultDataItem_Add", "Company", new { Id = ViewBag.CompanyId })) .Destroy(update =&gt; update.Action("CompanyDefaultDataItem_Delete", "Company")) ) ) </code></pre> <p>And here is the Add/Edit Template and my attempt to do what I want in script:</p> <pre><code>@{ Layout = null; } @model VW40.Web.Models.CompanyDefaultDataItemViewModel @Html.HiddenFor(model =&gt; model.CompanyId) &lt;br /&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Type) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Type, new { @id = "typeDropdown_Id" }) @Html.ValidationMessageFor(model =&gt; model.Type) &lt;/div&gt; &lt;br /&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Data) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.Data, new { style = "width:250px" }) @Html.ValidationMessageFor(model =&gt; model.Data) &lt;/div&gt; &lt;br /&gt; &lt;div style="padding-left:50px"&gt;Instructions:&lt;/div&gt; &lt;div id="instructions" style="width:200px"&gt; @Model.Instructions &lt;/div&gt; &lt;br /&gt; &lt;div style="padding-left:50px"&gt;Description:&lt;/div&gt; &lt;div id="description" style="width:200px"&gt; @Model.Description &lt;/div&gt; &lt;script type="text/javascript"&gt; $('#typeDropdown_Id').click(function () { var typeId = $('#typeDropdown_Id option:slected').val(); alert("selected type = " + typeId); $.getJSON("/Company/GetJsonCompanyDefaultDataItemTypeInstructionsAndDescription/" + typeId, function (data) { $('#instructions').val(data.Instructions); $('#description').val(data.Description); }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload