Monday, February 1, 2010

Get the text from dropdown in mvc asp.net

Get the value after dropdown value change.

there is very simple steps to get the dropdownlist value in controller at onChange event.

1) create the dropdownlist in .ASPX page.

Like:


id of the dropdownlist: ddl.
2) write the ajax call :


$(document).ready(function() {
$("#ddl").change(function() {
var text = $("#ddl> option:selected").attr("text");
$.ajax({
url: "/Controller/Action/",
data: 'ddlValue=' + text ,
type: 'GET',
dataType: 'html'
});
});

and the you can pass the ddlValue in the action method and you can get the text value of the drop down.

Hope its helpful. njoy the coding...




No comments:

Post a Comment