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:
Here is my editor template in the editortemplates views folder:
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.
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>
}
{
@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>
}