I'm building a custom pagination mechanism and I have a dropdown for changing the page size. The page size is represented in my viewmodel. Obviously I can change the value and run the search again to get the appropriate results.
But is there a way to make the DropDownListFor post back when the selected value is changed?
You can use HtmlATtributes passing "onchange();" Try this.
<%: Html.DropDownListFor(model => model.ProductName, listobj,
new { onchange = 'submit()'; }) %>
Hope this helps.
I actually wrote a little javascript to startup this behavior:
$(document).ready(function () {
$('form').find('select.auto-post').change(function () {
$(this).parents('form').submit();
});
});
Funny coincidence, I'm actually working on the same thing right now. However, I would suggest that you don't use the POST HTTP method for any kind of paging parameters. Use GET instead. This makes navigation easier for your users, and it makes it easier for search engines to index all pages of your content.
UPDATE:
For the above jquery to work, you would render your dropdownlist like this:
Html.DropDownListFor(expression, items, new { @class = "auto-post" })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With