Problem getting multiselect values to the controller

3 posts, 0 answers
  1. Mattias Hermansson
    Mattias Hermansson avatar
    24 posts
    Member since:
    May 2010

    Posted 03 Jan 2014 Link to this post

    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. Mattias Hermansson
    Mattias Hermansson avatar
    24 posts
    Member since:
    May 2010

    Posted 03 Jan 2014 Link to this post

    I found the problem, so this one is now solved.
  3. Kendo UI is VS 2017 Ready
  4. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 15 Apr 2014 in reply to Mattias Hermansson Link to this post

    What was your solution?
Back to Top