DropDownTree asp net get controller

1 Answer 157 Views
DropDownTree
Вадим
Top achievements
Rank 1
Iron
Iron
Вадим asked on 26 Dec 2021, 10:02 AM | edited on 26 Dec 2021, 10:35 AM

 

there is a form.Added element DropDownTree. When you click on the confirmation, you need to get the value in the controller Category. Preferably in the format string []. Tell me how you can get values, even in a different format.Thank you. 


<form asp-action="CreateService" asp-controller="ServiceSubmit" asp-antiforgery="true" data-ajax="true" data-ajax-method="post" data-ajax-update="#result_login_register" >
                        <input name="IsValid" type="hidden" value="@ViewData.ModelState.IsValid.ToString()" />
                        <div class="form-group">
                            <label asp-for="Name">Краткое название</label>
                            <input asp-for="Name" class="form-control" />
                            <span asp-validation-for="Name" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label>Категория</label>
                            @(Html.Kendo().DropDownTree()
                                .Name("Category")
                                .DataTextField("Category")
                                .HtmlAttributes(new { style = "width: 100%" })
                                .AutoClose(false)
                                .Checkboxes(checkboxes => checkboxes
                                    .Name("checkedFiles")
                                    .CheckChildren(true)
                                )
                                .DataSource(dataSource => dataSource                                    
                                    .Model(model => model
                                        .Id("IdCategory")
                                        .HasChildren("HasChildren")
                                    )
                                    .Read(read => read
                                        .Action("CategoryPodServic_Read", "ServiceSubmit")
                                    ).ServerFiltering(false)
                                )
                            )
                            @*<span asp-validation-for="Category.CategoryPod" class="text-danger"></span>*@
                        </div>
                        <div class="form-group">
                            <input asp-for="Raion" class="form-check-input" type="checkbox" value="" id="Raion">
                            <label class="form-check-label" for="Raion">
                                Выезд на район
                            </label>
                        </div>
                        <div class="form-group">
                            <label asp-for="Description">Описание</label>
                                @(Html.Kendo().Editor()
                                    .Name("Description")
                                    .HtmlAttributes(new { style = "width: 100%; height:400px" })
                                    .Tools(tools => tools
                                        .Clear()
                                        .Bold().Italic().Underline()
                                        .JustifyLeft().JustifyCenter().JustifyRight()
                                        .InsertUnorderedList().InsertOrderedList()
                                    )
                                )
                            <span asp-validation-for="Description" class="text-danger"></span>
                        </div>
                        <button class="btn btn-success" type="submit" >Сохранить</button>
                    </form>


1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 29 Dec 2021, 03:43 PM

Hello Vadim,

Thank you for the provided code snippet.

The selected items in the DropDownTree will be received through the submitted form in the "CreateService" Action Method as an array of strings when the data type of the "Value" property is string.

For example:

//Model
    public class OrderViewModel
    {
        public int OrderID { get; set; }
        public TreeItemViewModel Category { get; set; }
    }

    public class TreeItemViewModel
    {
        public string Id { get; set; }
        public string Value { get; set; }
        public string Text { get; set; }
    }

//View
        @(Html.Kendo().DropDownTree()
          .Name("Category")
          .DataTextField("Text")
          .DataValueField("Value")
          ...
        )

//Controller
[HttpPost]
public IActionResult CreateService(string[] Category)
{
  ...
}

If you have any further queries, don't hesitate to let me know.

Regards, Mihaela Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DropDownTree
Asked by
Вадим
Top achievements
Rank 1
Iron
Iron
Answers by
Mihaela
Telerik team
Share this question
or