Jobi
Jobi

Reputation: 1122

How do I get the selected value of a DropDownList (kendo) in a controller class?

How do I get the selected value of a DropDownList (kendo) in a controller class?

@(Html.Kendo().DropDownListFor(model => model.SchemeType)
   .Name("SchemeType")
   .BindTo(new List<string>() {
      "Sale",
      "Purchase"
    })
  )

Upvotes: 0

Views: 2302

Answers (2)

Petur Subev
Petur Subev

Reputation: 20233

If you put the DropDownList inside a form element it will be automatically send to the server, all you need to do is to add parameter to the method signature which uses the same name

e.g.

<form>
    @(Html.Kendo().DropDownListFor(model => model.SchemeType)
       .Name("SchemeType")
       .BindTo(new List<string>() {
          "Sale",
          "Purchase"
        })
      )
</form>

controller

public ActionResult (string SchemeType)

Upvotes: 1

MustafaP
MustafaP

Reputation: 6633

You can send parameter to controller from view with ajax but it's not possible directly take parameter from controller.

JS Function

var selectedValue = $("#SchemeType").data("kendoDropDownList").dataItem($("#SchemeType").data("kendoDropDownList").select());

        $.ajax({
            url: '@Url.Action("FunctionName", "ControllerName")',
            type: 'POST',
            dataType: "json",

            data: { SV : selectedValue },
            success: function (result) {
                if (result.Success) {
                    ....
                    }
                else {
                    ...
                }
            }
        })

Controller Function

public JsonResult FunctionName (string SV)
        {

            ...
            return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
        }

Upvotes: 0

Related Questions