0

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

1
  • ignore my ans ! i missed the mvc part ! blush Commented Dec 30, 2009 at 10:48

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

If you are not using Jquery then use Ajax post method directly//POST http.open("POST", url, true);
Thanks Pankaj, but instead of <select>, i have used <%=Html.DropDownList...>. Then i did the same as you have said above. But unfortunately it's not working for me.
@@Kapil you are not using JQuey that's why your $.post is not working.Please use ajax post. see this article to use ajax post viralpatel.net/blogs/2008/12/…
0

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

2 Comments

Thanks Brian. I am using Javascript to handle onchange event. How can i do so there?
try doing _doPostBack('<Select element name>', '<command>') and see if that works. That is a part of the MS Ajax framework and so you need to reference that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.