Q:

call a method in some .cs file for Dropdownlistfor onchange event

I have a static class ItemInitializer that has a method CreateCookie().  I want to call this method whenever the selected item in the dropdownlist change.  How do I do that in mvc?  
Currently, I am trying with this
In View:  
    @Html. DropDownListFor(m => m.SelectedItem, Model. MyItemList, new { @id = "ddLForItems"})

In Controller the method is called like this,
       myModel. SelectedItem = ItemInitializer. CreateCookie();

Now, onchange event for the DropDownListFor , the createCookie method needs to be called again. 
With jquery, how do I call the CreateCookie method.  I have, 
<script type = "text/javascript">
            $(function () {
                $("#ddLForItems").change(function () {
                    var item = $(this).val();
                    ...? 

                   //TBD:Create a cookie with value myModel. SelectedItem 

                });
            });

</script>

Thanks

A:

You could use the window.location.href to redirect to a controller action on your application that will call this method:
<script type = "text/javascript">
    $(function () {
        $('#ddLForItems').change(function () {
            var item = $(this).val();
            var url = '@Url. Action("SomeAction", "SomeController")?value=' + encodeURIComponent(item);
            window.location.href = url;
        });
    });
</script>

which will redirect to the following controller action and pass the selected value to it:
public ActionResult SomeAction(string value)
{
    ... you could call your method here
}

Alternatively if you don't want to be redirecting away from the current page you could use an AJAX call:
<script type = "text/javascript">
    $(function () {
        $('#ddLForItems').change(function () {
            var item = $(this).val();
            $.ajax({
                url: '@Url. Action("SomeAction", "SomeController")',
                type: 'POST',
                data: { value: item },
                success: function(result) {
                    // the controller action was successfully called 
                    // and it returned some result that you could work with here
                }
            });
        });
    });
</script>

