Click here to Skip to main content
11,478,902 members (74,070 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
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 12-Sep-12 23:08pm
Comments
vyas_pratik20 at 13-Sep-12 5:43am
   
you want to submit the page or you want to send it using ajax request.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If this Helps:

$(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" }); 
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 200
1 F-ES Sitecore 195
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,880
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100