简体   繁体   English

使用jQuery将列表从列表框传递到MVC控制器

[英]pass list from listbox to mvc controller with jquery

I would like to know how I can pass a list with values in MVC method via jquery. 我想知道如何通过jquery在MVC方法中传递带有值的列表。 I have a jquery UI dialog in which records are pasted in each row. 我有一个jQuery UI对话框,其中记录粘贴在每一行中。 Once the user will click the submit button, I want to have a jquery which will post the values from the popup multiline textbox to the method. 一旦用户单击“提交”按钮,我想要一个jquery,它将把弹出的多行文本框中的值发布到方法中。 Is that possible? 那可能吗? Thanks in advance, Laziale 在此先感谢Laziale

Yes it can be done simply get the values from the list and pass the to the controller. 是的,可以简单地从列表中获取值并将其传递给控制器​​来完成。

your java script will look something like this: 您的Java脚本将如下所示:

$('#submit').click(function() {
        //parsing and collecting the values from the list
        var values = { 'values': 'your string array here'};

         $.ajax({
        type: "GET",
        cache: false,
        url: "/controller/YourAction",
        dataType: "json",
        traditional: true,
        data: values
    });
    });

and you will have such an action in the controller: 并且您将在控制器中执行以下操作:

[HttpGet]
    public JsonResult YourAction(string[] values)
    {
        //your action here
        return Json("success", JsonRequestBehavior.AllowGet);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM