We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How can i find out what was selected in a list box in asp mvc

is there any documentation on this i cant seem to find anything.
here is the code of my view so far

@model List<BusinessLayer.Employee>

    @Html.EJ().ListBox("list1").Datasource(Model).ClientSideEvents(e => { e.SelectIndexChanged("selected"); })
 
    <p id="demo">JavaScript can change HTML content.</p>
    <script type="text/javascript">
        function selected(args)
        {
            document.getElementById('demo').innerHTML = "selecteditemtext"
        }
    </script>

eventually i want to filter a grid based on the item selected or return the selected item to the controller.

thanks
andrew

3 Replies

ES Ezhil S Syncfusion Team May 1, 2015 06:13 PM UTC

Hi Andrew,

Thank you for contacting Syncfusion support.

Yes, we can pass the selected item in ListBox to controller page using Ajax post from the client side script. Define the script using AJAX post under the ListBox’s “Selected” client side event. In the controller post action we can get the data passed through the AJAX post. Please refer the code snippet below,
<code>
[CSHTML]
@Html.EJ().ListBox("list1").TargetID("carsList").ClientSideEvents(e=>e.SelectIndexChanged("onSelected"))
[Script]

<script type="text/javascript">

function onSelected(args) {

litem = args.data.selectedText; // selected item text

$.ajax({

type: "POST",

url: "ListBoxFeatures",

content: "application/json; charset=utf-8",

dataType: "json",

data: { selectedtext: litem },

complete: function (d) {

$("#mydata").text(litem);

}

});

}
</script>
[Controller]

//Post action to get the data passed from AJAX post

[HttpPost]

public ActionResult ListBoxFeatures(string selectedtext)

{

string Listboxitem = selectedtext;

return View();
}
</code>

Simple sample prepared can be downloaded from the link below:
http://www.syncfusion.com/downloads/support/forum/118978/ListBox_f118978_(2)-1621988663.zip

Please let us know if you have any other queries.

Regards,
Ezhil S



AS Andrew Simpson May 5, 2015 08:33 AM UTC

Thank You.
Thats just what i needed.


KC Kasithangam C Syncfusion Team May 6, 2015 04:52 AM UTC

Hi Andrew,

Thanks for your update. Please let us know if you have further queries. We will be happy to help you out.

Regards,
Kasithangam

Loader.
Live Chat Icon For mobile
Up arrow icon