This is a migrated thread and some comments may be shown as answers.

dropdown lists null in editor templates.

1 Answer 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chrys
Top achievements
Rank 1
Chrys asked on 08 Apr 2013, 02:13 PM
So how would I handle dropdowns in the editor template. Every time my editor template is intialized my selectlist for my dropdowns are null. Do I need to set up an empty list and populate on the dropdown on edit in jquery?

Here is my grid:
@(Html.Kendo()
                          .Grid(Model.Activity.MediaForms)
                          .Name("MediaIterations")
                          .HtmlAttributes(new { @style = "primaryGridStyle" })
                          .Columns(columns =>
                          {
                              columns.Bound(form => form.Date).Format("{0:mm/yyyy}").Title("Month");
                              columns.Bound(form => form.Name).Title("Ad Name");
                              columns.Bound(form => form.TopicDesc).Title("Message Topic");
                              columns.Bound(form => form.TypeDesc).Title("Media Type");
                              columns.Bound(form => form.OutletName).Title("Media Outlet");
                              columns.Bound(form => form.TimesAdRan).Title("Runs");
                              columns.Command(command => { command.Edit(); command.Destroy(); });
                          })
                          .Editable(edit => edit.Mode(GridEditMode.PopUp).TemplateName("AddEditMediaForm"))
                          .ToolBar(toolbar => toolbar.Create())
                          .DataSource(datasource => datasource
                                                              .Ajax()
                                                              .ServerOperation(false)
                                                              .Model(model => model.Id(form => form.Id))
                                                              .Create(create => create.Action("AddMediaForm", "Form", new { planActivityId = Model.Activity.PlanActivityID }))
                                                              .Destroy(destroy => destroy.Action("DeleteMediaForm", "Form", new { planActivityId = ViewBag.planActivityId }))
                                                              .Update(destroy => destroy.Action("DeleteMediaForm", "Form", new { planActivityId = ViewBag.planActivityId })))
                    )


Here is my editor template in the editortemplates views folder:

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>MediaForm</legend>
        <div>
            <label>Month ads ran @Html.TextBoxFor(model => model.Month, new { @placeHolder = "mm",@columns="2" })/@Html.TextBoxFor(model=>model.Year,new{@placeHolder="yyyy", @columns="4"})</label>
            <label>Ad Name @Html.TextBoxFor(model => model.Name)</label>
        </div>
        <div>
            <label>
                Message Topic
                <select id="MediaTopic" name="TopicId">
                    @foreach (var category in Model.MediaCategoriesList)
                    { 
                        <optgroup label="@category.CategoryDesc">
                            @foreach (var topic in category.TopicsList)
                            {
                                
                                <option value="@topic.Value" selected="@topic.Selected">@topic.Text</option>
                            }
                        </optgroup>
                    }

                </select></label>
            <label>Ad Runs @Html.TextBoxFor(model=>model.TimesAdRan)</label>
        </div>
        <div>
            <label>Media Type @Html.DropDownListFor(model => model.TypeId, Model.TypeList, new { @id = "mediaTypes" })</label>
        </div>
        <div>
            <label>Media Outlet @Html.DropDownListFor(model=>model.OutletID,Model.OutletList)</label>
        </div>
    </fieldset>
}
if I don't set the dropdown intially in my view all my dropdownlist are null and produce an exception. Is there anyway around this.

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 10 Apr 2013, 08:18 AM
Hi Chrys,

 
Basically to achieve the desired behavior using PopUp editor template I would suggest to use the KendoUI DropDownList widget and load it's data from the controller. For such example you can check this demo in our CodeLibrary.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Chrys
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or