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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

118978 Apr 30,2015 08:24 AM May 6,2015 12:52 AM ASP.NET MVC 3
loading
Tags: ListBox
Andrew Simpson
Asked On April 30, 2015 08:24 AM

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

Ezhil S [Syncfusion]
Replied On May 1, 2015 02:13 PM

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


Andrew Simpson
Replied On May 5, 2015 04:33 AM

Thank You.
Thats just what i needed.

Kasithangam C [Syncfusion]
Replied On May 6, 2015 12:52 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;