I would like to disable the DropDownListFor which is cascading from another dropdownlist in editor while editing a record and keep it enable while in adding a record. I am using Kendo Grid in my MVC project.
Here I would like to disable Country Dropdownlist and location dropdownlist when in edit mode and keep enable when in add(insert new record) mode
The code is as below:
Grid:
@(Html.Kendo().Grid<Webapplication1.Models.mainViewModel>()
.Name("mainGrid")
.Columns(c =>
{
c.Bound(m => m.Id).Hidden();
c.Bound(m => m.CountryViewModel.CountryName)
.Title("Country").HeaderHtmlAttributes(new { @title = "Countries" });
c.Bound(m => m.LocationViewModel.LocationName)
.Title("Location").HeaderHtmlAttributes(new { @title = "Locations" });
c.Command(p =>
{p.Edit().Text(" ").UpdateText(" ").CancelText(" ").HtmlAttributes(new { @title = "Edit" });});
})
.ToolBar(toolbar => { toolbar.Create().Text("").HtmlAttributes(new { @title = "Add"}); })
.Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.PopUp).TemplateName("gridEditor"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("mainGrid_Read", "abc"))
.Update(update => update.Action("mainGrid_Update", "abc"))
.Create(create => create.Action("mainGrid_Create", "abc"))
.Model(m => { m.Id(p => p.Id);
m.Field(p => p.CountryViewModel).DefaultValue(ViewData["DefaultCountry"] as Webapplication1.Models.CountryViewModel);
})
)
)
Country DropDownList:
@model Webapplication1.Models.CountryViewModel
@(Html.Kendo().DropDownListFor(m => m)
.AutoBind(false)
.OptionLabel("Select")
.DataValueField("CountryId")
.DataTextField("CountryName")
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("GetCountries", "abc").Type(HttpVerbs.Post))
.ServerFiltering(true);
})
)
@Html.ValidationMessageFor(m => m)
Location DropDownList:
@model Webapplication1.Models.LocationViewModel
@(Html.Kendo().DropDownListFor(m => m)
.OptionLabel("Select")
.DataValueField("LocationId")
.DataTextField("LocationName")
.AutoBind(false)
.DataSource(d =>
{
d.Read(read =>
{
read.Action("GetLocationsByCountryId", "abc").Type(HttpVerbs.Post).Data("getCountryId");
}).ServerFiltering(true);
})
.CascadeFrom("CountryViewModel")
)
@Html.ValidationMessageFor(m => m)
Popup editor:
@model Webapplication1.Models.mainViewModel
<table>
@Html.HiddenFor(m => m.Id)
<tr>
<td>@Html.Label("Country:")</td>
<td>@Html.EditorFor(m => m.CountryViewModel)</td>
</tr>
<tr>
<td>@Html.Label("Location:")</td>
<td>@Html.EditorFor(m => m.LocationViewModel)</td>
</tr>
</table>
DropDownListFor(m => m)? Is this inside and EditorTemplate? - ataravati