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

Post selected values to controller

1 Answer 436 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Austin
Top achievements
Rank 1
Austin asked on 08 Jun 2016, 08:13 PM

I seem to be having a problem posting the selected values from my Kendo Multiselect widget to an action on my controller. I've never had this issue before and as far as I know I am doing everything right, but something is obviously causing an issue.

I have this input on my view:

<input id="ProductHandlingTypes" name="ProductHandlingTypes" style="width: 100%"/>

 

Here is my viewmodel:

public class BuyerProfileViewModel
{
    public string UserId { get; set; }
    public string Name { get; set; }
    public int BuyerTypeId { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zipcode { get; set; }
    public string Description { get; set; }
    public List<int> ProductHandlingTypes { get; set; }
 
    public bool Producer { get; set; }
}

 

JavaScript:

$("#ProductHandlingTypes").kendoMultiSelect({
    placeholder: "-- Select Type(s) --",
    dataTextField: "Name",
    dataValueField: "Id",
    dataSource: new kendo.data.DataSource({
        transport: {
            read: {
                url: "/Helper/GetProductHandlingTypes",
                dataType: "json",
                type: "GET"
            }
        }
    })
});
 
$("#btnSave").on("click", function (e) {
    e.preventDefault();
    var formCreate = $(".form-register-buyer");
    formCreate.validate();
 
    if (formCreate.valid()) {
        var options = {
            url: $(formCreate).attr("action"),
            type: $(formCreate).attr("method"),
            data: $(formCreate).serialize()
        };
 
        $.ajax(options)
            .done(function(data) {
                if (data.success === true) {
                    window.location.href = data.redirectTo;
                } else {
                    toastr.options = { "postiionClass": "toast-bottom-full-width" };
                    toastr.error(data.message, "Uh, Oh!");
                }
            });
    }
});

 

And a snippit of my controller:

[HttpPost]
public ActionResult BuyerProfile(BuyerProfileViewModel model)
{
    if (ModelState.IsValid)
    {
        // do stuff here
    }
}

 

All of the rest of the values post to the controller just fine. But when I hover over the model this is what I see for "ProductHandlingTypes" (I've attached a screenshot)

 

 

1 Answer, 1 is accepted

Sort by
0
Austin
Top achievements
Rank 1
answered on 09 Jun 2016, 02:13 PM
Figured it out. I needed to change it from an <input> to a <select multiple>. Now all of the values are being posted to the controller.
Tags
MultiSelect
Asked by
Austin
Top achievements
Rank 1
Answers by
Austin
Top achievements
Rank 1
Share this question
or