How to bind and call selected event of dropdownlist in MVC 3

//Bind dropdown on layout page

@if (Session["List of data"] != null)
                {
                    @Html.DropDownList("Dropdown ID", Session["List of data"] as SelectList)
                }

then create controler and write your business logic.



//Dropdown change event on Layout(master)
//calling controler

<script type='text/javascript'>
    $(document).ready(function () {


        $('#Dropdown ID').change(function () {
            var v1 = $(this).val();
            if (v1 != $('#hidden control ID').val()) {
                var url = '/controler name/action name/' + v1;
                window.location.replace(url);
             
            }

        });
    });

 
</script>



Set dropdown value as selected true  on Layout(master).....



@if (Session["Dropdown selected value"] != null)
{
    @Html.Hidden("hdnDrp", Session["Dropdown selected value"].ToString());
    <div>
    <script type="text/javascript">
        $(document).ready(function () {
            var v = $('#hidden control ID').val();
            if (v != null)
                $('#Dropdown ID').val(v);

        });
    </script>
    </div>
}




Comments

Popular posts from this blog

How to convert filr into arrary of byte and save again it in file.

How to debug Windows services in Visual Studio?

Auto generate change scripts in SQL Server Management Studio SSMS for tables