Click here to Skip to main content
15,562,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am begginer to MVC.I want to call controller method from view.
Following is my controller method
C#
public List<SelectListItem> GetCardTypes(string defaultValue)
    {

        if (defaultValue =="FPS")
        {
            items.Add(new SelectListItem { Text ="scft/min" Value ="scft/min"});           
        }
        else
        {
            items.Add(new SelectListItem { Text = "Nm/hr", Value ="Nm/hr" });           
        }
        return items;
    }


In View I will write script as follows
JavaScript
<script type="text/javascript">

    $(function () {

        $("#DDUnit").change(function (evt)
        {
            var DropDownSelectedVal = $("#DDUnit :selected").val();           
            if (DropDownSelectedVal !=null)
            {
                $.ajax({
                    url:"abc/GetCardTypes",
                    type: 'POST',
                    data: { "ParameterYouWantToPass" : DropDownSelectedVal },
                    success: function (response)
                     {                       
                     }
            });
        }
        });
    });
</script>

I want when function is successfully executed,return value that is "items" which has return type "List <SelectListItem>".I want to use that items which is return by controller method.
Posted
Updated 12-Feb-14 22:42pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900