Click here to Skip to main content
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 Kornfeld Eliyahu Peter 265
1 Sergey Alexandrovich Kryukov 202
2 George Jonsson 185
3 King Fisher 185
4 CPallini 155
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2014
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