Reputation: 1879
can anyone please help me about how to invoke a post method on changing the drop down list selection? I have Index method in my controller which takes me to index page. There i have placed a dropdown list using Html.Dropdown containing items like 1,2,3,etc. I want to call post method for Index whenever i makes any selection from the dropdown.
regards, kapil
Upvotes: 0
Views: 2091
Reputation: 4505
You can do this using JQuery
<select id="idXYZ" name="XYZ" onchange="SetUnit(this.value)">
<%= ViewData["YourValue"]%>
</select>
Now use JQuery
<script type="text/javascript">
function SetUnit(unit) {
$.post("/Admin/YourMethod?itemid=" + unit.toString(), function(data) {
var data = eval('(' + data + ')');
$("#idunit").html(data.Value);
});
}
</script>
Upvotes: 1
Reputation: 50728
Are you using JQuery? You could use $.post to post your data in the onchange event... I think in the web forms way it was using a _doPostBack call in the onchange event if you set AutoPostBack to true... not 100% sure about that.
HTH
Upvotes: 0