[RESOLVED]dropdownlist selected item value and text in MVC controller

how to get selected items text in httppost controller actionresult

i m getting value of it but not text ho to get it

i have bind it using VeiwBag from httpget

but how to fetch text of it

do i have to add heddenfield or name field

 

Hi,

Create a text field and set the style to display "none" and set the text box value with the drop down selected text

<input type='text' style='display:none' name='SelectedText' />
$("input[type=text][name=SelectedText]").val($("#DropDownList option:selected").text());

when you submit you can access the drop down selected text along with the value as well.

pjpatil

do i have to add heddenfield or name field

Yes you can use hiddenfield

on change of dropdown, change the value of hidden with the selected text. then hidden will be posted with key of hidden name

<input type='hidden' name='DropDownListText' id='DropDownListText' />
$(document).ready(function(){
    $("#DropDownList").change(function(){
        $("#DropDownListText").val($(this).text());
    });
});

thanks both the answers are working owsome

for the first answer i have to use change event to get the changed data

Leave a Reply