如何在MVC3中使用javascript调用动作方法并传递数组?

时间:2012-09-06 11:38:32

标签: asp.net-mvc-3

大家好我单击一个按钮时想要做的,这个按钮将数组的值从控制器传递给View。但是如何使用javascript调用控制器动作并传递数组?

这是我在控制器中的动作方法:

public ActionResult Index()

        {
            TahakkukServicesClient client = new TahakkukServicesClient();
            client.ClientCredentials.UserName.UserName = "service_test";
            client.ClientCredentials.UserName.Password = "..";
            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
            MakbuzList[] liste = client.GetMakbuzListe(2);
            return View(liste);
        }

我的观点:

    @model IEnumerable<MakbuzList>
    @using icerik.TahakkukServices       

    @{

        ViewBag.Title = "E-Belediye";
        Layout = "~/Views/Shared/Ecouncil.cshtml";

    }
    <script type="text/javascript">

        ????????????

</script>
    <li><a class="collapsed">Description</a>
                    <ul>
                        <li><a href="#">Button1</a></li>

                    </ul>
               </li>

1 个答案:

答案 0 :(得分:1)

将onclick操作绑定到按钮,该按钮会向您的Index方法触发ajax GET请求并解析结果。在MVC Index操作中,返回ViewResult,返回Json。 如图所示here