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

Problem getting multiselect values to the controller

2 Answers 178 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Mattias Hermansson
Top achievements
Rank 1
Mattias Hermansson asked on 03 Jan 2014, 07:36 AM
Hello,

I'm using a multiselect and i have a problem returning the value of the multiselect to the controller while using a ajax call.
          @(Html.Kendo().MultiSelect()
.Name("BaPaymentMachine")
.Placeholder("Please choose BA")
.DataTextField("Id")
.DataValueField("Id")
.DataSource(ds => ds.Read("GetAllBaPayment", "Report"))
.HtmlAttributes(new { @style = "width:200px;" }))
Model
public class SearchViewModel
{
    public List<string> BaPaymentMachine { get; set; }
}
Controller
[HttpGet]
[OutputCache(Duration = 0)]
public ActionResult _GetReportPartial(SearchViewModel model)
{
    do stuff to model
 
    return PartialView(model);
}
Ajax call
var ba = $("#BaPaymentMachine").val();
 alert("ba:" + ba);
        $.ajax({
            type: "GET",
            url: '@Url.Action("_GetReportPartial", "Report")',
            data: { BaPaymentMachine: ba },
            cache: false,
            success: function (data) {
                var newBox = "<div id='reportmap' class='width:100%'>" + data + "</div>";
                $("#result").html(newBox);
                $(".loaderrepport").fadeOut("slow");
            },
            error: function () {
                showerror("There was a problem getting the values, please try again.");
                $(".loaderrepport").fadeOut("slow");
            }
        });
    });
If i run this with an empty multiselect i get an empty string, but with values it returns null in the controller. Also the alert before the ajax call returns all the values perfectly, the version that i'm currently using 2013.3.1119.545

2 Answers, 1 is accepted

Sort by
0
Mattias Hermansson
Top achievements
Rank 1
answered on 03 Jan 2014, 10:08 AM
I found the problem, so this one is now solved.
0
King Wilder
Top achievements
Rank 2
answered on 16 Apr 2014, 04:15 AM
What was your solution?
Tags
MultiSelect
Asked by
Mattias Hermansson
Top achievements
Rank 1
Answers by
Mattias Hermansson
Top achievements
Rank 1
King Wilder
Top achievements
Rank 2
Share this question
or