Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to pass the selected value of dropdown list to controller.

The drop down in view is as follows;

<div>
    <label>Page Size</label>

    @Html.DropDownList("pageSizes", HRMS.Areas.EIM.Controllers.RouteController.PageSizeSelectList(), new { onchange = "onPageSizeChange()" }) rows per page    
    <p></p>


</div>


capture the change event value as follows;

<script>

    $(function onPageSizeChange() {
        $('#pageSizes').change(function () {
            var selectedValue = $(this).val();
            $('#pageSizes').val(selectedValue);
            $.post("/Route/SaveEntry", selectedValue); 

            //alert(selectedValue);
            $('form').submit(); 

        });
    });

    }    
 

</script>



How to pass this selected value to controller??Please help me.
Posted
Comments
vyas_pratik20 13-Sep-12 5:43am    
you want to submit the page or you want to send it using ajax request.

1 solution

If this Helps:

HTML
$(function() {    
$("#submit").click(function () 
{         
	$.ajax	({             
		url: this.href,            
 		type: 'POST',             
		data: { input: $('#dropdown').val() },
                success: function (result) {   alert(result.name);   },       
		error: function () { alert("error");    }        
 		});     
   	return false;     
}); 
}); 

[HttpPost] 
public ActionResult submit(string input) 
{    
	var result = _db.Ingredients.Where(i => i.IngredientName == input); 
  	return Json(new { name = "Hello There" }); 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900