Submit MultiSelect Data to Controller POST
|Product||MultiSelect for ASP.NET Core, MultiSelect for ASP.NET MVC|
If I would like to submit selected data then how I can pass selected data to the controller action method? Essentially, how to get the values in the multiselect on a submit postback to my controller.
The Kendo MultiSelect widget is a
<select multiple> element in the DOM and so it will POST a list of fields with the values of the selected options. The controller must be prepared to take such input.
There are different ways to pass data to a controller in MVC and here are a few:
- Use a form and a submit button in it like you would with a simple
<select multiple>element. This works best if the html helper you use is an editor for a model field (for example,,
MultiSelectFor(model => model.TheField)which will let you use the MVC model binding to post the entire model from the form. Here are two samples:
- Create your own request where you can read the value of the multiselect and pass it as a generic string (you can get it from its value() method). An example of obtaining that is also available in the samples above.
- Use an AJAX form with some additional scripts which basically goes through the inputs on the page and serializes them: https://www.c-sharpcorner.com/UploadFile/0c1bb2/ajax-beginform-in-Asp-Net-mvc-5/. This is quite similar to the idea above, although you may need to test how these scripts behave with a