<div class="form-group">
@Html.LabelFor(model => model.categoria, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-2">
@Html.EJ().DropDownList("categoria").TargetID("categorie").Width("100%").PopupHeight("280px").WatermarkText("Seleziona una categoria").ClientSideEvents(
e => e.Create("dropDownCategoriaOnCreate")).ReadOnly(disableControls)
<div id="categorie">
<ul>
@Html.EJ().TreeView("treeViewCategoria").TreeViewFields(
s => s.Datasource(ds => ds.URL(@Url.Action("DataSource", "Categorie", new { tipoArticolo = Model.tipoArticolo })).Adaptor(AdaptorType.UrlAdaptor))
.Id("IDcategoria").Text("categoria").ParentId("IDcategoriaParent").HasChild("hasChild").Expanded("expanded").Selected(Model.IDcategoria.ToString())).ClientSideEvents(
e => e.NodeSelect("categoriaSelect").Create("treeViewCategoriaOnCreate").Ready("treeViewCategoriaReady").NodeExpand("checkScroll").NodeCollapse("checkScroll"))
</ul>
</div>
@Html.ValidationMessageFor(model => model.IDcategoria, "", new { @class = "text-danger" })
</div>
</div> <script>
// -------- dropDown categoria section ----------- //prevents the default behaviour to perform custom action ej.DropDownList.prototype._OnMouseClick = function (e) { } ej.DropDownList.prototype._OnMouseEnter = function (e) { } ej.DropDownList.prototype._OnMouseLeave = function (e) { } ej.DropDownList.prototype._OnKeyUp = function (e) { } ej.DropDownList.prototype._OnKeyDown = function (e) { } function dropDownCategoriaOnCreate(args) { drpdwnobj = this; } function treeViewCategoriaOnCreate(args) { treeobj = this; } function treeViewCategoriaReady(args) { var node = treeobj.getNode($("#@Model.IDcategoria")); //imposta il valore corretto all'apertura della form categoriaSelect(node); } //per far apparire le barre di scorrimento quanto si espande la treeView function checkScroll(args) { var scrolpos = drpdwnobj.scrollerObj.model.scrollTop; drpdwnobj._refreshScroller(); drpdwnobj.popupList.css("display", "block"); drpdwnobj.scrollerObj.setModel({ "scrollTop": scrolpos }); } function categoriaSelect(args) { if (!ej.isNullOrUndefined(args)) { var currentText = !ej.isNullOrUndefined(args.text) ? args.text : args.value;//recupera il testo dal nodo selezionato var currentValue = args.id; //recupera l'ID del nodo selezionato drpdwnobj.clearText(); drpdwnobj._hiddenValue = currentText; //adding the current value to hidden element drpdwnobj._addText(currentText); // adding the text to dropdownlist drpdwnobj.model.value = currentText; //setting value in model $("#IDcategoria").val(currentValue); //assegna il valore al campo contenente l'ID categoria drpdwnobj._hideResult(); } } //^^^^^^^^^^ dropDown categoria section ^^^^^^^^
</script>
Can you help me ?
To recreate the issue in your sample,
set "true" for the UnobtrusiveJavaScriptEnabled key in web.config
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
include the ~/Scripts/ej/ej.unobtrusive.min.js in _Layout.cshtml