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

Value of dropdownlist

1 Answer 18 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Elena
Top achievements
Rank 1
Elena asked on 11 Apr 2018, 07:46 PM

Hello,

 I started to use dropdownlist Kendo but your documentation is confusing and I cannot find an info that I am looking for.

 I created 

@(Html.Kendo().DropDownListFor(d => d.AppraisalType)
                    .Name("optional")
                    .OptionLabel("Select Appraisal Type")
                    .HtmlAttributes(new { @class = "form-control", id = "typeAppraisal" })
                    .BindTo(new List<string>() {
        "60 Days Appraisal",
        "6 Months Appraisal",
        "Yearly Appraisal"
    })

When I submit the form it is not in database, saved as null. How I can save it?

And another thing how to set up dropdownlist as required field? 

Thank you!


1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 13 Apr 2018, 09:53 AM
Hello Elena,

If I had correctly understood the issue that you are experiencing - it is related with passing the selected value to the controller on form submit. I am afraid that I was unable to replicate such an issue locally - the value of the dropdown list is correctly passed to the action, using the example below.

Also, regarding the validation - I would advise using kendo validator for achieving this. In addition, make sure that the required attribute is set for the dropdown list.

    <form id="form" action="~/Home/SubmitForm" method="post">
 
    @(Html.Kendo().DropDownListFor(d => d.An)
                    .Name("optional")
                    .OptionLabel("Select Appraisal Type")
                    .HtmlAttributes(new { @class = "form-control", id = "typeAppraisal", required = "required" })
                    .BindTo(new List<string>() {
                        "60 Days Appraisal",
                        "6 Months Appraisal",
                        "Yearly Appraisal"
                    })
    )
 
    <button id="validateButton" type="button" class="k-button">validate</button>
    <button type="submit" class="k-button">submit</button>
 
    <script>
 
        $(document).ready(function () {
            var validator = $("#form").kendoValidator()
 
            $("#validateButton").click(function (e) {
                e.preventDefault(); 
                var validator = $("#form").data('kendoValidator'); 
                validator.validate(); 
            });
        })
 
 
    </script>
</form>

Please refer to validation demo below:

https://demos.telerik.com/aspnet-mvc/validator

Regards,
Nencho
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownList
Asked by
Elena
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or